Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JCache CacheResultInterceptor does not allow null values to be cached [SPR-13641] #18218

Closed
spring-projects-issues opened this issue Nov 4, 2015 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 4, 2015

Rosendo Alvarez opened SPR-13641 and commented

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";
}

Affects: 4.2.2

Attachments:

1 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 9, 2015

Stéphane Nicoll commented

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 9, 2015

Stéphane Nicoll commented

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.

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2.3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants