Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-13641

JCache CacheResultInterceptor does not allow null values to be cached

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.2.2
    • Fix Version/s: 4.2.3
    • Component/s: Caching
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      When using jcache annotations to cache the results of a method call using ehcache as the caching implementation, the caching of null values is not allowed even though the JCacheCacheManager explicitly has an option to "allowNullValues".

      App context:

      <cache:annotation-driven />
      <bean id="cacheManager" class="org.springframework.cache.jcache.JCacheCacheManager">
      	<property name="allowNullValues" value="true" />
      </bean>
      

      dependencies:

      <dependency>
      	<groupId>org.springframework</groupId>
      	<artifactId>spring-context-support</artifactId>
      </dependency>
      <dependency>
      	<groupId>org.ehcache</groupId>
      	<artifactId>jcache</artifactId>
      	<version>1.0.1</version>
      </dependency>
      <dependency>
      	<groupId>net.sf.ehcache</groupId>
      	<artifactId>ehcache</artifactId>
      	<version>2.10.1</version>
      </dependency>
      

      @CacheResult(cacheName = "reserveTypes")
      public String findReserveTypeByName(String reserveTypeName) {
      	if (reserveTypeName == "test") {
      logger.info("This is not being retrieved from cache.");
      		return null;
      	}
      return "this will be cached";
      }
      

      1. ehcache.xml
        0.4 kB
        Rosendo Alvarez

        Activity

        Hide
        snicoll Stéphane Nicoll added a comment -

        it should be noted that this only happens with the standard annotations for some reason. If you use @Cacheable this works fine now.

        Show
        snicoll Stéphane Nicoll added a comment - it should be noted that this only happens with the standard annotations for some reason. If you use @Cacheable this works fine now.
        Hide
        snicoll Stéphane Nicoll added a comment -

        This is now fixed. Please note that the JCache spec does not allow you to store "null" in a JSR-107 cache so sensu stricto you're not spec compliant if that's you want to do.

        That being said, it's just a detail and we could store a placeholder instead of null. That's what we were doing before anyway, the only problem that I just fixed is that the JSR-107 annotations interceptor did not allow that.

        It does now, can you give the next 4.2.3.BUILD-SNAPSHOT a try please? Should be available in the next couple of hours.

        Show
        snicoll Stéphane Nicoll added a comment - This is now fixed. Please note that the JCache spec does not allow you to store "null" in a JSR-107 cache so sensu stricto you're not spec compliant if that's you want to do. That being said, it's just a detail and we could store a placeholder instead of null . That's what we were doing before anyway, the only problem that I just fixed is that the JSR-107 annotations interceptor did not allow that. It does now, can you give the next 4.2.3.BUILD-SNAPSHOT a try please? Should be available in the next couple of hours.

          People

          • Assignee:
            snicoll Stéphane Nicoll
            Reporter:
            rjalvare Rosendo Alvarez
            Last updater:
            Stéphane Nicoll
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 15 weeks, 5 days ago