Yes there is a working, but not yet simple, implementation of caching. It can use a combination of memcache and in-memory caching (using a Guava cache)
I have added a @Cache annotation but not yet wired it up to register the cached entity.
Instead you must register it directly yourself like this:
- Create a Configuration class (MyConfiguration extends DefaultConfiguration) which you pass into the constructor of your ObjectDatastore.
- Register the cached types only once like this
private MyConfiguration()
{
if (!BaseObjectDatastore.isKindCached(typeToKind(Messages.class)))
{
BaseObjectDatastore.registerCachedKind(typeToKind(Messages.class), 300, 0, true, true);
}
}
Sorry its a bit messy to do this! The only reason it needs to be in your configuration class is so that it has to be passed into the OD constructor and you need access to typeToKind(). You could however, just hard code the kind name and put the registration code in a static initialiser for your DAO.
The parameters mean:
- String kind: kind to cache
- int seconds: how long to store items for in memory and memcache
- int maximum: max number of items to store in-memory (i.e. not in memcache)
- boolean automatic: is the cache used automatically (the other option is to only use it when it is explicitly turned on for a particular operation)
- boolean global: should we store in memcache? (if false, only use local in-memory cache)
I use it in production so it is quite stable but just not pretty to configure yet.
John