Uploaded image for project: 'Commons JCS'
  1. Commons JCS
  2. JCS-193

[JCACHE] How to configure caches used by interceptors (i.e. CacheResultInterceptor) related to JCache annotations

    XMLWordPrintableJSON

Details

    Description

      I started using JCS cache as a JCache implementation provider a few days ago and everything was fine until I needed to set up expiration for cached data or even the number of elements stored in the cache. I realized that caches were created with EternalPolicy so I started to figure out how to set up both implementation specific properties and Standard JCache ones. After a couple of days, I don't have a pretty idea about how to configure the caches related to methods annotated with JCache annotations like CacheResult, CacheRemove and so on.

      I mean that I already know that I can use the CacheDefaults annotation, both at class and method level, in order to set the name of the cache to be used. but another thing is to also set the CacheResolverFactory. Should I always set the CacheResolverFactory in the annotation in order to be able to create the cache using a specific set of properties? Or maybe the idea is to create the cache programmatically before is is needed? Anyway, It seems too much boilerplate to me. Maybe I am wrong but I think that we are not using the CDI power at all.

      please, let me know if there is better/simpler approach.

      Another thing that I cannot understand is the readConfig method of the JCSCachingManager class. It is loading the folder structure because it is loading the resources from the default uri of the provider! 

      where uri is "jcs://jcache.ccf", so the path is "/". I think that this URI should not be used for this, maybe the uri should be something different (URI of the default configuration?) or just use another implementation specific property.  Notice that adding an extra slash will look for /jcache.ccf file! maybe it is just a bug and there is a slash missing : "jcs:///jcache.ccf"

       final Enumeration<URL> resources = loader.getResources(uri.getPath());
      

       

      What about this?

      Add CachingProvider and CacheManager as beans if they are not already beans. Notice that this is what jcs-jcache-extras module already does! 

      So as a developer I can configure my CachingProvider and even the cache manager already configured as beans.  They will be injected where needed instead of being created without configuration.

      no configuration in CacheResolverFactory 

      public CacheResolverFactoryImpl()
      {
        provider = Caching.getCachingProvider();
        cacheManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader());
      }
      

      but in JCacheFilter class some properties are set

       

      manager = provider.getCacheManager(URI.create(uri), classLoader, properties);
      

      One step further into CDI should be to also provide the CacheResolverFactory as a bean and also the 

      CacheResolverFactoryImpl could be also injected with the cacheProvider and CacheManager and some CompleteConfigurationResolver of something like that in order to avoid creating caches with a hard-coded MutableConfiguration. 

      public class CacheResolverFactoryImpl implements CacheResolverFactory
      {
      ...
      private Cache<?, ?> createCache(final String exceptionCacheName)
      {
        cacheManager.createCache(exceptionCacheName, new   MutableConfiguration<Object, Object>().setStoreByValue(false));
        return cacheManager.getCache(exceptionCacheName);
      }
      

       

       with these changes, we reduce boilerplate and give more control to jcs-jcache library clients.

       Can we move ExtraJCacheExtension to jcs-jcache in order to be able to handle CachingProvider and CacheManager as beans?

      best regards,

      Ricard

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rnacher Ricard Nàcher Roig
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m