0
votes

I am using GAE for my server where I have all my entities in Datastore. One of the entity has more than 2000 records, and it is taking almost 30 secs to read whole entity. So I wanted to use cache to improve performance.

  1. I have tried Datastore objectify @cache annotation, but not finding how to read from the stored cache. I have declared entity as below:

    @Entity
    @Cache
    public class Devices{
    }
    
  2. Second thing I tried is memcache. I am storing whole List s in key, but this is not storing, I couldn't see in console memcache, but at the same time not showing any errors or exceptions while storing objects.

    putvalue("temp", List<Devices>)
    
    public void putValue(String key, Object value) {
        Cache cache = getCache();
        logger.info(TAG + "getCache() :: storing memcache for key : " + key);
        try {
          if (cache != null) {
            cache.put(key, value);
          }
        }catch (Exception e) {
          logger.info(TAG + "getCache() :: exception : " + e);
        }
    }
    

    When I tried to retrieve using getValue("temp"), it is returning null or empty.

    Object object =  cache.get(key);
    

My main object is to limit the time to 5secs to get all the records of entity. Can anyone suggest what I am doing wrong here? Or any better solution to retrieve the records fast from Datastore.

1

1 Answers

0
votes
  1. Datastore Objectify actually uses the App Engine Memcache service to cache your entity data globally when you use the @Cache annotation. However, as explained in the doc here, only get-by-key, save(), and delete() interact with the cache. Query operations are not cached.
  2. Regarding the App Engine Memcache method, you may be hitting the limit for the maximum size of a cached data value which is 1 MiB, although I believe this raise an exception indeed.

Regarding the query itself, you may be better off using a keys_only query and then doing a key.get() on each returned key. That way, Memcache will be used for each record.