the keyset() function
omerzohar Dec 30, 2010 7:25 AMi was running a small test to see how eviction works. my goal is to have a cache of X items in memory, in LRU mode, and infinite number of entries evicted to back store (basically it is an in-memory LRU cache).
here's my config file (grid-config.xml):
<namedCache name="persistant"> <clustering mode="distribution"> <stateRetrieval timeout="60000" fetchInMemoryState="false"/> <sync/> <hash numOwners="2"/> <l1 enabled="true"/> </clustering> <loaders passivation="false" shared="true" preload="true"> <loader class="org.infinispan.loaders.file.FileCacheStore" fetchPersistentState="false" purgeOnStartup="false"> <properties> <property name="location" value="${jboss.server.data.dir}${/}blackbox.cache"/> </properties> </loader> </loaders> <eviction wakeUpInterval="600000" maxEntries="2" strategy="LRU"/> <expiration lifespan="86400000" maxIdle="-1"/> </namedCache>
i ran the following code:
EmbeddedCacheManager manager = new DefaultCacheManager("d:\\grid-config.xml" ); Cache<String,String> data = manager.getCache("persistant"); data.clear(); System.out.println(data.getConfiguration().getEvictionStrategy().name()); System.out.println(data.getConfiguration().getEvictionMaxEntries()); data.put("b", "bb"); data.put("a", "aa"); data.put("c", "cc"); data.put("d", "dd"); System.out.println(data.keySet()); Thread.sleep(1000); data.put("d", "dd"); System.out.println(data.keySet()); data.put("e", "ee"); System.out.println(data.keySet()); Thread.sleep(1000); System.out.println(data.size()); for (String c : new String []{"a","b","c","d","e"}){ System.out.println(data.containsKey(c)); System.out.println(data.get(c)); }
the result is:
LRU 2 [c, d] [c, d] [d, e] 2 true aa true bb true cc true dd true ee
i was wondering about the keyset() function. although it seems that all keys are present with the get/contains function, the keyset() returned is always the size of 2. my guess is this is what resides in memory?
if that's the case when i ran 'data.get("a")', this means the data was pulled from the persistant store?
is there a way that i can know when a get request was answered from memory and when it was from persistant?