I'm using @Cacheable
annotation to store in cache some methods
<cache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="method1" />
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="method2" />
</set>
</property>
</bean>
But Once several users use the application 's cache is full thereby blocking the application. Is there any way to limit the size of cache and if yes do this may affect the application's data?
Interface CacheManagerSpring's central cache manager SPI. Allows for retrieving named Cache regions.
The @EnableCaching annotation triggers a post-processor that inspects every Spring bean for the presence of caching annotations on public methods. If such an annotation is found, a proxy is automatically created to intercept the method call and handle the caching behavior accordingly.
JCache is a de facto standard Java cache API for caching data. Also known as JSR 107 (i.e., a “Java Specification Request” from the “Java Community Process” [JCP]), this API implementation is intended to create a way for different technologies to provide a common caching interface.
Unfortunately ConcurrentMapCache
which is produced by ConcurrentMapCacheFactoryBean
doesn't allow to limit its size.
ConcurrentMapCache
Simple Cache implementation based on the core JDK java.util.concurrent package. Useful for testing or simple caching scenarios
I'd suggest using something more powerfull like EhCache-based Cache or Guava Cache (if you use Spring 4.0 +).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With