caching - Guava Cache - maximumSize - Eviction (LRU or most often) -


I am planning to use guava cache in my application. Some of these [K, V] which are entered are statistically; Gt; & Gt; Compared to others and should always be available in the cache. According to the sample of

If your cache should not exceed a certain size, then only use the cachebuilder. Maximum size (long) The cache will try to expel those entries which have not been used lately or too many times

I am trying to understand the often section. Can I suppose - For the cache of maximum size = 100 , if Key_A has reached 10000 and immediately after the post 100 call, Key_A still be present in the cache? The original unit test I did not confirm this fact. Any ideas?

  Public class cache helper {Private cache & lt; String, string & gt; Cash; Public Cash Helper (cache) = cache. Maximize (10) .comcommercial (1) .bild (); } Public string fetchVal (string key) {string val = cache.getIfPresent (key); Return valve; } Public Zero PutVal (string key, string value) {cache.put (key, val); }}   

test

  public class CacheTest {public static zero main (string [] args) {cache helper cache heller = new cache helper (); CacheHelper.putVal ("0", "0"); {CacheHelper.fetchVal ("0") for (int i = 0; i & lt; 10000; i ++); } System.out.println (cacheHelper.fetchVal ("0")); For (int i = 1; i <-11; i ++) {string key = "" + i; CacheHelper.putVal (key, key); } System.out.println (cacheHelper.fetchVal ("0")); // still return zero - "is not being used most often?" }}   

thanks

LRU uses the Removal Policy

In the key entry for your key, "0" became the oldest value when you added 10 new values ​​and therefore the old value of the cash was ejected, Which reached its maximum size.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -