public static Cache getCache() { if(CacheProvider.cache == null){ synchronized (CacheProvider.class){ if(CacheProvider.cache == null){ CacheProvider.cache = getDefaultCache(); } } } return CacheProvider.cache; }
private static Cache getDefaultCache(){ return new LRUCache(400); //return new NOOPCache(); } }
public void put(String key, JsonPath value) { JsonPath oldValue = map.put(key, value); if (oldValue != null) { removeThenAddKey(key); } else { addKey(key); } if (map.size() > limit) { map.remove(removeLast()); } }
private JsonPath pathFromCache(String path, Predicate[] filters) { Cache cache = CacheProvider.getCache(); String cacheKey = Utils.concat(path, new LinkedList<Predicate>(asList(filters)).toString()); JsonPath jsonPath = cache.get(cacheKey); if (jsonPath == null) { jsonPath = compile(path, filters); cache.put(cacheKey, jsonPath); } return jsonPath; }
@Test public void issue_94_2() throws Exception { LRUCache cache = new LRUCache(5); cache.put("1", dummy); cache.put("2", dummy); cache.put("3", dummy); cache.put("4", dummy); cache.put("5", dummy); cache.put("6", dummy); cache.get("1"); cache.get("2"); cache.get("3"); cache.get("4"); cache.get("5"); cache.get("6"); cache.get("2"); cache.get("3"); cache.get("4"); cache.get("5"); cache.get("6"); cache.get("3"); cache.get("4"); cache.get("5"); cache.get("6"); cache.get("4");
public JsonPath get(String key) { JsonPath jsonPath = map.get(key); if(jsonPath != null){ removeThenAddKey(key); } return jsonPath; }
public void remove(String key) { removeFirstOccurrence(key); map.remove(key); }
public void put(String key, JsonPath value) { JsonPath oldValue = map.put(key, value); if (oldValue != null) { removeThenAddKey(key); } else { addKey(key); } if (map.size() > limit) { map.remove(removeLast()); } }
@Override public <T> T read(String path, Predicate... filters) { notEmpty(path, "path can not be null or empty"); Cache cache = CacheProvider.getCache(); path = path.trim(); LinkedList filterStack = new LinkedList<Predicate>(asList(filters)); String cacheKey = Utils.concat(path, filterStack.toString()); JsonPath jsonPath = cache.get(cacheKey); if(jsonPath != null){ return read(jsonPath); } else { jsonPath = compile(path, filters); cache.put(cacheKey, jsonPath); return read(jsonPath); } }
private static Cache getDefaultCache(){ return new LRUCache(400); //return new NOOPCache(); } }
public static Cache getCache() { if(CacheProvider.cache == null){ synchronized (CacheProvider.class){ if(CacheProvider.cache == null){ CacheProvider.cache = getDefaultCache(); } } } return CacheProvider.cache; }
public JsonPath get(String key) { JsonPath jsonPath = map.get(key); if(jsonPath != null){ removeThenAddKey(key); } return jsonPath; }
public void remove(String key) { removeFirstOccurrence(key); map.remove(key); }
public void put(String key, JsonPath value) { JsonPath oldValue = map.put(key, value); if (oldValue != null) { removeThenAddKey(key); } else { addKey(key); } if (map.size() > limit) { map.remove(removeLast()); } }
private static Cache getDefaultCache(){ return new LRUCache(400); //return new NOOPCache(); } }
public static Cache getCache() { if(CacheProvider.cache == null){ synchronized (CacheProvider.class){ if(CacheProvider.cache == null){ CacheProvider.cache = getDefaultCache(); } } } return CacheProvider.cache; }
public JsonPath get(String key) { JsonPath jsonPath = map.get(key); if(jsonPath != null){ removeThenAddKey(key); } return jsonPath; }
public void remove(String key) { removeFirstOccurrence(key); map.remove(key); }