3

I seem to remember reading somewhere that google app engine automatically caches the results of very frequent queries into memory so that they are retrieved faster.

Is this correct?

If so, is there still a charge for datastore reads on these queries?

Chris Dutrow
  • 48,402
  • 65
  • 188
  • 258

3 Answers3

5

If you're using Python and the new ndb API, it DOES have automatic caching of entities, so if you fetch entities by key, it would be cached:

http://code.google.com/appengine/docs/python/ndb/cache.html

As the comments say, queries are not cached. Cached requests don't hit the datastore, so you save on reads there.

If you're using Java, or the other APIs for accessing the datastore, then no, there's no caching.

edited Fixed my mistake about queries getting cached.

dragonx
  • 14,963
  • 27
  • 44
  • 3
    Actually, NDB caches entities, but not queries: "Queries do not look up values in any cache. However, query results are written back to the in-context cache if the cache policy says so (but never to Memcache). " – Nick Johnson Mar 14 '12 at 00:10
  • 2
    What Nick says. Rick Mangi's answer is correct. You may be able to get some benefit from NDB's cache by using a keys_only query and passing the results to get_multi(); however see the discussion about this here: http://code.google.com/p/appengine-ndb-experiment/issues/detail?id=118 . – Guido van Rossum Mar 14 '12 at 03:46
1

I think that app engine does not cache anything for you. While it could be that, internally, it caches some things for a split second, I don't think you should rely on that.

I think you will be charged the normal number of read operations for every entity you read from every query.

Riley Lark
  • 20,660
  • 15
  • 80
  • 128
1

No, it doesn't. However depending on what framework you use for access to the datastore, memcache will be used. Are you developing in java or python? On the java side, Objectify will cache GETs automatically but not Queries. Keep in mind that there is a big difference in terms of performance and cachability between gets and queries in both python and java.

You are not charged for datastore reads for memcache hits.

Rick Mangi
  • 3,761
  • 1
  • 14
  • 17