tags:

views:

298

answers:

1

Hello

I have this configuration for ehCache:

<ehcache>
    <defaultCache
            name="defaut"
            maxElementsInMemory="5"
            eternal="false"
            timeToIdleSeconds="20"
            timeToLiveSeconds="20"
            overflowToDisk="false"
            diskPersistent="false"
            memoryStoreEvictionPolicy="LRU"
            />           
</ehcache>

How can I get access to default cache of EhCache?

CacheManager.getInstance().getCache("default"); // returns null
+2  A: 

My understanding is that the "default cache" is actually a template for new caches that get created, rather than being a specific named cache.

CacheManager.getCache will only return a cache instance if it has already been created, so you'll need to tell it to create a new one, using something like addCacheIfAbsent(). The name doesn't matter, it will be created on demand using the default cache settings.

skaffman