views:

278

answers:

1

Since there is no way to join tables using Google App Engine datastore, I loop over a list of entities and look up the related entities one-by-one using the foreign key value.

for (Employee staff: staffList){
   Employee manager = pm.getObjectById(Employee.class, staff.getManagerId());
}

There is a good chance that I will be needing the same referenced entity more than once, and I do not want to go to the datastore twice for the same entity.

Is there some kind of session cache that I can enable to eliminate the duplicate lookups, or do I have to roll my own?

+1  A: 

JDO the spec does mandate caching of instances within a PersistenceManager, according to datanculeus, who provided help with the app engine JDO functionality:

link to datanucleus cache page

However, I know that there ares still some things missing from the appengine implementation, as mentioned here:

app engine unsupported features

The good news is that caching doesn't seem to be on that list. The bad news is that I couldn't find confirmation that level 1 caching is implemented. It shouldn't be that hard to test though - time your code getting 100 different entities, then time it getting the same entity 100 times.

Peter Recore
I'l try that. Probably do not even need to time it, because Google bills you per API call, so you can actually see how many calls the page did in your quota summary.
Thilo
brilliant! let us know how it worked out so you can save the next guy some trouble!
Peter Recore
L1 and L2 caching are implemented since that part is in DataNucleus "core" jar. L2 caching is not turned on by default
DataNucleus
sweet. thanks for the official confirmation andy.
Peter Recore