Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EhCache default cache in java

Tags:

java

ehcache

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
like image 261
user349302 Avatar asked Jun 02 '10 19:06

user349302


People also ask

Is Ehcache local cache?

The cache acts as a local copy of data retrieved from or stored to the system-of-record. This is often a traditional database, although it might be a specialized file system or some other reliable long-term storage. For the purposes of using Ehcache, the SOR is assumed to be a database.

Where does Ehcache store data?

Data stores supported by Ehcache include: On-Heap Store - Utilizes Java's on-heap RAM memory to store cache entries. This tier utilizes the same heap memory as your Java application, all of which must be scanned by the JVM garbage collector.

How do you check the size of cache in Ehcache?

In EhCache 3 (at least in the 3.5 version that I uses) you can access cache size via the cache statistics.

Is Ehcache in memory?

1. Overview. In this article, we will introduce Ehcache, a widely used, open-source Java-based cache. It features memory and disk stores, listeners, cache loaders, RESTful and SOAP APIs and other very useful features.


1 Answers

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.

like image 68
skaffman Avatar answered Oct 02 '22 14:10

skaffman