3
votes

i have a simple question

in the objectify documentation it says that "Only get(), put(), and delete() interact with the cache. query() is not cached" http://code.google.com/p/objectify-appengine/wiki/IntroductionToObjectify#Global_Cache.

what i'm wondering - if you have one root entity (i did not use @Parent due to all the scalability issues that it seems to have) that all the other entities have a Key to, and you do a query such as

ofy.query(ChildEntity.class).filter("rootEntity", rootEntity).list()

is this completely bypassing the cache?

If this is the case, is there an efficient caching way to do a query on conditions - or for that matter can you cache a query with a parent where you would have to make an actual ancestor query like the following

Key<Parent> rootKey = ObjectifyService.factory().getKey(root)
ofy.query(ChildEntity.class).ancestor(rootKey)

Thank you


as to one of the comments below i've added an edit

sample dao (ignore the validate method - it just does some null & quantity checks):

this is a sample find all method inside a delegate called from the DAO that the request factory ServiceLocator is using

public List<EquipmentCheckin> findAll(Subject subject, Objectify ofy, Event event) {
  final Business business = (Business) subject.getSession().getAttribute(BUSINESS_ATTRIBUTE);
  final List<EquipmentCheckin> checkins = ofy.query(EquipmentCheckin.class).filter(BUSINESS_ATTRIBUTE, business)
    .filter(EVENT_CONDITION, event).list();
  return validate(ofy, checkins);
}

now, when this is executed i find that the following method is actually being called in my AbstractDAO.

/**
* 
* @param id
* @return
*/
public T find(Long id) {
  System.out.println("finding " + clazz.getSimpleName() + " id = " + id);
  return ObjectifyService.begin().find(clazz, id);
}
1

1 Answers

6
votes

Yes, all queries bypass Objectify's integrated memcache and fetch results directly from the datastore. The datastore provides the (increasingly sophisticated) query engine that understands how to return results; determining cache invalidation for query results is pretty much impossible from the client side.

On the other hand, Objectify4 does offer a hybrid query cache whereby queries are automagically converted to a keys-only query followed by a batch get. The keys-only query still requires the datastore, but any entity instances are pulled from (and populate on miss) memcache. It might save you money.