简体   繁体   中英

Spring Cache Manager add new cache without anotations

I can get items out of the cache manager by using

cachemanager.getCache("cachename").get(cacheKey)

How do I add a new cache via the cache manager? There appears to be only getCache() and getCacheNames() .

There is getCache("newcachename").put(cacheKey) but that fails as "newcachename" doesn't exist.

我不完全知道您的配置是什么样子,因此无法给出更详细的说明,但是我已经使用Spring的CompositeCacheManager成功地使用了多个缓存

  <set>
    <bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="newcachename" />
  </set>

Have you set up this cache for this cacheName in the configurations?

Sorted, my fault. I didnt add the new cache details to the ehcache.xml file.

<cache name="newcachename" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="300" overflowToDisk="false" diskPersistent="false"/>

Once I added this I could use

getCache("newcachename").put(cacheKey, "value to cache")

Thanks all for your assistance.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM