Skip to content

Commit

Permalink
#287 Remove cacheNull Annotation parameter and related.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregrluck committed Dec 13, 2013
1 parent c32af3b commit c298ab5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 33 deletions.
Expand Up @@ -99,19 +99,7 @@ public Object cachePut(CacheContextSource<I> cacheContextSource, I invocation) t
protected void cacheValue(final InternalCacheKeyInvocationContext<? extends Annotation> cacheKeyInvocationContext,
final CachePutMethodDetails methodDetails, final Object value) {

final Object cachedValue;
if (value == null) {
if (methodDetails.getCacheAnnotation().cacheNull()) {
//Null values are cached, set value to the null placeholder
cachedValue = CacheContextSource.NULL_PLACEHOLDER;
} else {
//Ignore null values
return;
}
} else {
cachedValue = value;
}

final Object cachedValue = value;

final CacheResolver cacheResolver = methodDetails.getCacheResolver();
final Cache<Object, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext);
Expand Down
Expand Up @@ -69,9 +69,7 @@ public final Object cacheResult(CacheContextSource<I> cacheContextSource, I invo
if (!cacheResultAnnotation.skipGet()) {
//Look in cache for existing data
result = cache.get(cacheKey);
if (cacheResultAnnotation.cacheNull() && CacheContextSource.NULL_PLACEHOLDER.equals(result)) {
return null;
} else if (result != null) {
if (result != null) {
//Cache hit, return result
return result;
}
Expand All @@ -87,8 +85,6 @@ public final Object cacheResult(CacheContextSource<I> cacheContextSource, I invo
//Cache non-null result
if (result != null) {
cache.put(cacheKey, result);
} else if (cacheResultAnnotation.cacheNull()) {
cache.put(cacheKey, CacheContextSource.NULL_PLACEHOLDER);
}

return result;
Expand Down
Expand Up @@ -29,10 +29,6 @@
* @since 1.0
*/
public interface CacheContextSource<I> {
/**
* Placeholder used for caching a null value
*/
NullPlaceholder NULL_PLACEHOLDER = NullPlaceholder.INSTANCE;

/**
* Get information about an invocation annotated {@link javax.cache.annotation.CacheResult},
Expand Down Expand Up @@ -64,15 +60,4 @@ public interface CacheContextSource<I> {
*/
StaticCacheInvocationContext<? extends Annotation> getMethodDetails(Method method, Class<? extends Object> targetClass);


/**
* Used to cache null values, there should never be more than the single INSTANCE
*/
public enum NullPlaceholder {
/**
* Null Placeholder for use with {@link javax.cache.annotation.CachePut} and
* {@link javax.cache.annotation.CacheResult}
*/
INSTANCE;
}
}

0 comments on commit c298ab5

Please sign in to comment.