如何在Go AppEngine中将数据存储区查询存储到内存缓存?

I'm working on Appengine with Golang.

I have about 1000 entities on datastore.

When I query all entities(q.GetAll(...)), Datstore Read Operations or Datastore Small Operations run about 2% usage(1k of 50k). It's same when I use KeysOnly() or Project(..something...).

I have read some articles to solve this, I have to store Datastore Query to memcache. But I cannot find how to do that.

So how can I store/retrieve Datastore Query to/from memcache in Go AppEngine?

Or is there other way to decrease datastore read/small operation usage?

I need your help. Thank you.

The best practice is to make a query with KeysOnly() and caching each call datastore.Get() for the key.

The algorithm is as follows:

  • after adding entity, add it to the cache by her own key
  • in obtaining check it in cache
    • if no, then get out it from datastore and add it back into the cache
    • if there is use it from cache

How to use memcache described in the documentation.

Queries are not cached. If your entity are small, you can reduce use a projection query and reduce to small costs. Check out the end of the article for information about generating the necessary search index.