8

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?

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
user3816170
  • 319
  • 12
  • 20

1 Answers1

5

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 +).

Evgeny
  • 2,483
  • 1
  • 17
  • 24
  • can you give me example of using config XML. with SimpleCacheManager we use in bean org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean for GUAVA Cache What are we gonna use? – user3816170 Apr 21 '16 at 15:44
  • @user3816170 see this question http://stackoverflow.com/questions/28296839/config-spring-cache-using-guava – Evgeny Apr 21 '16 at 15:50