I generate RSS feed with latest 10 records from GAE NDB datastore. Records in database are updated weekly. How can I avoid queries to datastore each time user requests RSS feed display? I.e. how to cache that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use memcache to avoid hitting the datastore every time. As you probably know queries are not cached in NDB.
https://developers.google.com/appengine/docs/python/memcache/usingmemcache
So in other words, try to get your data from memcache and if it fails get it from the datastore then add it to memcache for next time round.
The example above uses a 60 second timeout (the value 60 in the .add call) Simply leave that argument out to have the data persist as long as memcache allows.
Also from a similar question: NDB Caching When Using Projected Queries
So it appears if you get by key you’ll automatically get from the NDB cache instead, if available, but I’ve not personally used that.
So construct your RSS content and just before you render or it, save it to memcache. Then when you update the content it’s created from simply invalidate the cached version (see docs) so the next request will get it from the datastore and you can then put it back in the cache.