I'm using EhCache on a service's delegate with spring's annotations.
On my @Cacheable
annotation I've added a resolverFactoryName
field to resolve my cache at runtime.
Then I implement CacheableCacheResolver
interface, and return a cache depending of business rules, but sometimes I have no cache to return according to these rules.
If I return null EhCache's lib gave me a NPE. What is the way to do when I've no cache to return and so the app should no cache any of these values ? Is there a "fake" cache to return? Is there something like a NoCacheException to throw?
I do not think exception is the way to go, you really want to return a no-op cache implementation.
From the class name you give - CacheableCacheResolver
- it looks like you are using ehcache-spring-annotations
which does not seem to have support for what you want - a no-op cache.
Note that you can still take care of it yourself.
If you were to use the Spring Caching abstraction, you could use a similar system which has support for no-op caches through org.springframework.cache.support.NoOpCacheManager.NoOpCache
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.