Announcement Announcement Module
Collapse
No announcement yet.
using cache annotations with many cacheManagers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • using cache annotations with many cacheManagers

    We are integrating many modules into a single application. Each module defines its own spring config files and we are aggregating these config files into a single ApplicationContext.
    Some modules have defined a CacheManager linked to a eh-cache config file, and use annotation-driven for proxying beans that need caching.

    The problem we are facing in that although the cache-manager property is configurable, we must integrate many cache-managers, each one containing caches that are used by beans from different modules.

    As an example, consider module 1, which defines a bean with methods annotated with @Cacheable. Its spring config file contains <cache:annotation-driven cache-manager="module1CacheManager"/>, and the definitino of a cacheManager, named "module1CacheManager", linked to the eh-cache config file named "eh-cache-module1.xml". This config files defines a cache named "usersCache", together with other global properties.

    Another module (module 2) defines a bean that also uses cache with annotations. Thus it contains a spring config file with a cacheManager named "module2CacheManager" and <cache:annotation-driven cache-manager="module2CacheManager"/>. The CacheManager references a eh-cache config file with a cache named "countryCache".

    We need to integrate both modules into a single application with a single Spring application context. When I create an application context with xml files from both modules, 2 cache managers are defined, but the second <cache:annotation-driven/> tag is ignored (and the 2nd cache manager too) as the cache-namespace parser only registers 1 cache aop advisor.

    There should be a way to specify the cache-manager name to use on a class-level for classes that use @Cacheable annotations (with a default to "cacheManager"), and remove the cache-manager attribute from <cache:annotation-driven/>.

  • #2
    We too are facing the same issue, any updates on this?

    Comment


    • #3
      as you can see ... nope.

      I have created a jira with a proposal to support either @Qualifier or add a qualifier attribute to @Cacheable in order to be able to specify the cache manager name, in the same way it's done with @Transactional, and its value attribute.
      https://jira.springsource.org/browse/SPR-8696
      You can vote for it !

      Comment


      • #4
        Do you have a workaround now? We're trying to achieve something similar, but instead of having spring dependencies in all modules, we'll have a separate cache module to serve to other client modules for their caching needs. We're thinking to have one spring configuration in cache module, where it pulls properties files from other modules to configure caching, things like cache namespace, caching mechanisms, caching expireis, etc. However, we're not sure if this is all possible?

        Comment


        • #5
          HI All,

          Were you able to find any workaround for above mentioned problem?

          Regards,
          Mehak

          Comment


          • #6
            The jira issue is supposed to be fixed for 4.1.RC1 (see https://jira.springsource.org/browse/SPR-8696). You can vote for it.

            Meanwhile, we have found a workaround for this issue by turning things differently: the application that assembles the modules defines a unique CacheManager bean and declares <cache:annotation-driven> driven by that CacheManager. On the other end, the different modules that use caching only define a ehcache configuation file together with @Cachable annotations on their services. The CacheManager is created by assembling the configuration files from the modules it gathers, using net.sf.ehcache.config.Configuration.addCache(Cache Configuration).
            We have thus created our own CacheManager factorybean that has a property of type List<Resource> representing the ehcache configuration files. It concatenates these configuration files into a single Configuration object that is used to create the CacheManager, with the following code:


            Code:
            Iterator<Resource> i = this.configFiles.iterator();
            Resource firstConfigFile = i.next();
            Configuration conf = ConfigurationFactory.parseConfiguration(firstConfigFile.getURL());
            while (i.hasNext()) {
              Configuration next = ConfigurationFactory.parseConfiguration(i.next().getURL());
              for (CacheConfiguration cc : next.getCacheConfiguration().values()) {
                conf.addCache(cc);
              }
            }
            CacheManager cm = CacheManager.create(conf);
            It works for us.

            Comment

            Working...
            X