Calling memcache.set_multi_async doesn't save values

250 Views Asked by At

I'm currently using the Google memcache API in my Google Appsengine application to store a large amount of data in cache, however this needs to happen asynchronously as I need to return a result before it is done.

I already found an answer here stating how it is done, however I still can't get my code to work.

I tried using this, however it simply causes memcache to be store the values synchronously:

client = memcache.Client()
rpc = client.set_multi_async(values)
rpc.get_result()
return values[id]

I also tried this, but it causes memcache to never save the values:

client = memcache.Client()
client.set_multi_async(values, rpc=memcache.create_rpc())
return values[id]

Is there any way to store the values asynchronously and return a value at the same time? Thanks

1

There are 1 best solutions below

2
On

rpc.get_result() causes the rpc object to wait until the result is available before returning, thus making your code synchronous. In order to make your code asynchronous, you would need to return the rpc object(s) and then use the Future class to wait for and handle results when they are ready.