I use simple layer for loading and storing entities by key or id and I just added caching to this layer. When entity with given key is in the cache, return it rather then fetch from the datastore. And when the entity is updated and saved to datastore, the layer simply sets the entity in the cache to null. It's completely transparent.
It seems to be working fine, however the object fetched from the cache is slightly different from the object fetched from the datastore. Some things stopped working, for example and I can't use .contains() on Collections inside entity to check whether there is a relationship between two entities. I also encountered a weird behavior, when I loaded an object from cache and immediately after that stored to the datastore, all items in collections representing relationships were replaced with null
s. However I couldn't reproduce it. Now it's working fine.
I don't know what's happening under the hood, so the question is, is this way of working with cache reliable? Can I work with entities fetched from cache just like as they were fetched from the datastore (accessing children, updating, removing...)?