Allow null values to be cached with @CacheResult
Even though the JSR-107 spec forbids to store null values, our cache abstraction allows that behaviour with a special handled (and this is the default behaviour). While this was working fine with our own set of annotations, the JSR-107 interceptor counterpart was interpreting the spec sensu strictu. We now allow for that special case as well. Issue: SPR-13641
This commit is contained in:
@@ -38,6 +38,11 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object cacheNull(Object arg1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object conditional(int field) {
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -58,6 +58,12 @@ public class AnnotatedJCacheableService implements JCacheableService<Long> {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheResult
|
||||
public Long cacheNull(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheResult(exceptionCacheName = "exception", nonCachedExceptions = NullPointerException.class)
|
||||
public Long cacheWithException(@CacheKey String id, boolean matchFilter) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,8 @@ public interface CacheableService<T> {
|
||||
|
||||
T cache(Object arg1);
|
||||
|
||||
T cacheNull(Object arg1);
|
||||
|
||||
void invalidate(Object arg1);
|
||||
|
||||
void evictEarly(Object arg1);
|
||||
|
||||
@@ -40,6 +40,12 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable("testCache")
|
||||
public Long cacheNull(Object arg1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict("testCache")
|
||||
public void invalidate(Object arg1) {
|
||||
|
||||
Reference in New Issue
Block a user