/** * Constructor. * * @param name of file cache * @param minElementsInMemory keep this number in the cache * @param softLimit trigger a cleanup if it goes over this number. * @param hardLimit if > 0, never allow more than this many elements. This causes a cleanup to be done in the calling thread. * @param period if > 0, do periodic cleanups every this number of seconds. */ public FileCacheARC(String name, int minElementsInMemory, int softLimit, int hardLimit, int period) { this.name = name; this.minElements = minElementsInMemory; this.softLimit = softLimit; this.hardLimit = hardLimit; this.period = period; shadowCache = new ConcurrentSkipListMap<>(new CacheElementComparator()); cache = new ConcurrentHashMap<>(2 * softLimit, 0.75f, 8); files = new ConcurrentHashMap<>(4 * softLimit, 0.75f, 8); if (trackAll) track = new ConcurrentHashMap<>(5000); }
/** * Constructor. * * @param name of file cache * @param minElementsInMemory keep this number in the cache * @param softLimit trigger a cleanup if it goes over this number. * @param hardLimit if > 0, never allow more than this many elements. This causes a cleanup to be done in the calling thread. * @param period if > 0, do periodic cleanups every this number of seconds. */ public FileCacheARC(String name, int minElementsInMemory, int softLimit, int hardLimit, int period) { this.name = name; this.minElements = minElementsInMemory; this.softLimit = softLimit; this.hardLimit = hardLimit; this.period = period; shadowCache = new ConcurrentSkipListMap<>(new CacheElementComparator()); cache = new ConcurrentHashMap<>(2 * softLimit, 0.75f, 8); files = new ConcurrentHashMap<>(4 * softLimit, 0.75f, 8); if (trackAll) track = new ConcurrentHashMap<>(5000); }
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 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; }