0

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

Community
  • 1
  • 1
Paradoxis
  • 4,471
  • 7
  • 32
  • 66
  • Possible duplicate of [App Engine memcache async operation get\_multi\_async](http://stackoverflow.com/questions/7601471/app-engine-memcache-async-operation-get-multi-async) – Josh J Feb 23 '16 at 21:33

1 Answers1

0

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.

Josh J
  • 6,813
  • 3
  • 25
  • 47
  • Could you perhaps show an example of how this is implemented as I'm completely stuck on Google's documentation, thanks! – Paradoxis Feb 24 '16 at 07:56
  • There's an example [here](https://cloud.google.com/appengine/docs/python/ndb/async) - does that help? – tx802 Feb 24 '16 at 08:17