kasavbere
kasavbere

Reputation: 6003

In Python and GAE: How to permanently cache data from a Datastore across HTTP GET requests

I am developing an online product using GAE and Python. Certain data in my Model (i.e. Datastore) are constant across Contexts: which means for all incoming HTTP GET requests, those data don't change.

For the sake of argument, assume that said data must live in the Datastore as opposed to static pages (e.g html).

How would I set the Google App Engine Caching policies so that the Datastore is only queried once in the life of the application -- even if the product is experiencing millions of hits per day?

DISCLAIMER: I am a complete newbie to both Python and GAE.

I am presently looking into global variables, which I would use to store said query results. Not only do I not yet know how that would work, there is another problem: Different HTTP GET requests (i.e. urls) are for different portions and views of said constant data.

Thanks for any insight.

Upvotes: 0

Views: 229

Answers (1)

RocketDonkey
RocketDonkey

Reputation: 37269

You may want to take a look at the Memcache API. It will allow you to do basically what you want - cache the results of a query (or even the resulting page as HTML) and serve it while it is available (you can set an expiry, but you will also occasionally experience cache misses where the datastore is queried anyway). Also, as @voscausa mentions, switching your datastore API from db to ndb will provide automatic caching with additional options to further modify caching behavior (docs here).

Upvotes: 1

Related Questions