private void addToCache(Object hashKey, FileCacheable ncfile) { CacheElement newCacheElem = new CacheElement(hashKey); CacheElement previous = cache.putIfAbsent(hashKey, newCacheElem); // add new element if doesnt exist CacheElement elem = (previous != null) ? previous : newCacheElem; // use previous if it exists elem.addFile(ncfile); // add to existing list shadowCache.put(newCacheElem, newCacheElem); int size = cacheSize.getAndIncrement(); if (size > softLimit) { removeFromCache(size - softLimit); } }
public String toString() { return hashKey + " count=" + list.size()+ " countAccessed=" + countAccessed + " lastAccessed=" + new Date(getLastAccessed()); }
public String toString() { return hashKey + " count=" + list.size()+ " countAccessed=" + countAccessed + " lastAccessed=" + new Date(getLastAccessed()); }
private CacheElement updateInCache(CacheElement elem) { if (shadowCache.firstKey() == elem) return elem; elem.updateAccessed(); CacheElement prev = shadowCache.put(elem, elem); // faster if we could just insert at the top of the list. maybe we need to use LinkedList ? if (prev != null && (elem != prev)) { CacheElementComparator cc = new CacheElementComparator(); System.out.printf("elem != prev compare=%d%n", cc.compare(elem, prev)); System.out.printf("hash elem =%d prev=%d%n", elem.hashCode(), prev.hashCode()); } return elem; }
@Override public int compare(CacheElement o1, CacheElement o2) { return Misc.compare(o1.getLastAccessed(), o2.getLastAccessed()); } }
@Override public int compare(CacheElement o1, CacheElement o2) { return Misc.compare(o1.getLastAccessed(), o2.getLastAccessed()); } }
private CacheElement updateInCache(CacheElement elem) { if (shadowCache.firstKey() == elem) return elem; elem.updateAccessed(); CacheElement prev = shadowCache.put(elem, elem); // faster if we could just insert at the top of the list. maybe we need to use LinkedList ? if (prev != null && (elem != prev)) { CacheElementComparator cc = new CacheElementComparator(); System.out.printf("elem != prev compare=%d%n", cc.compare(elem, prev)); System.out.printf("hash elem =%d prev=%d%n", elem.hashCode(), prev.hashCode()); } return elem; }
private void addToCache(Object hashKey, FileCacheable ncfile) { CacheElement newCacheElem = new CacheElement(hashKey); CacheElement previous = cache.putIfAbsent(hashKey, newCacheElem); // add new element if doesnt exist CacheElement elem = (previous != null) ? previous : newCacheElem; // use previous if it exists elem.addFile(ncfile); // add to existing list shadowCache.put(newCacheElem, newCacheElem); int size = cacheSize.getAndIncrement(); if (size > softLimit) { removeFromCache(size - softLimit); } }