Be notified of new releases
Create your free GitHub account today to subscribe to this repository for new releases and build software alongside 31 million developers.Sign up
This release introduces JSR107 compatibility (see also here https://caluga.de/v/2018/5/20/custom_caching_in_morphium)
since the first version of Morphium it provided an internal cache for all Entities maked with the annotation
Cache. This cache was configured mainly via those annotations.
This cache has proven its usefulness in countless projects and the synchronizing of caches in clustered environments via Morphium Messaging is working flawlessly.
But there are new and more sophisticated Cache Implementations out there . It would not be clever to built all those features also into morphium, better leverage on those projects. So we decided to include JCache-Support (JSR107) into morphium.
Of course, we had to adapt some things here and there, especially the
MorphiumCahce-Interface needed to be overhauled.
Morphium itself always had the option to use an own MorphiumCache Implementation. But thsi was not always easy to achieve. But we use that now in order to be able to offer both the old, proven implementation and the new, future-implementation.
As always, morphium can be used out of the box, so we implemented a JCAche-Version of our cache as well into morphium.
##How to use
With the upcoming V3.2.2BETA1 morphium will use the JCache compatible implementation. If you want to switch back to the old, proved Version of caching, you just need to change the config:
MorphiumConfig cfg=new MorphiumConfig(); cfg.setCache(new MorphiumCacheImpl());
if you create your
MorphiumConfig via properties or via JSon, you need to set the class name accordingly:
If you leave all those settings to default, the JCache API is being used. By Default the cache creates the cache manager using
Caching.getCachingProvider().getCacheManager(). This way you get the default of the default
If you want to configure the cache on your own (ehcache properties for example), you just need to pass on the CacheManager to the morphiumCache:
CachingProvider provider = Caching.getCachingProvider(); morphium.getCache.setCacheManager(provider.getCacheManager());
of course in this example, there are no additional options set, but I think you see, how that might work.
BTW: the morphium internal JCache implementation can be used via JCache API in your application also, if you want to. Just add the system setting
-Djavax.cache.spi.CachingProvider=de.caluga.morphium.cache.jcache.CachingProviderImpl and with
Caching.getCachingProvider() you will get the Morphium Implementation of the cache.
All JCache implementation support expiration of oldest / least recently used entries in cache. Unfortunately the policy of morphium is a bit more complex (especially regarding the number of entries), so moprhium implements an own JCache-Housekeeping for now.
Whatever Cache Implementation you use, you might still use the CacheSynchronizer in order to synchronize caches. And this synchronization should be working via Mongo even if you are not storing any Entities!
There are some minor known bugs in the current Beta, you might want to know:
- the CacheListener Callbacks do not seem to work properly with JCache implementations. That is when using EHCache at least. The Morphium Internal implementation works
- there is a bug with Global Cache override Settings, that are not properly passed on to the underlying Caches
- Messaging seems sometimes be affected as well by that. For some reason, we get a mongo exception here and there