/** * 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 FileCache(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; cache = new ConcurrentHashMap<>(2 * softLimit, 0.75f, 8); files = new ConcurrentHashMap<>(4 * softLimit, 0.75f, 8); wantsCleanup = period > 0; if (wantsCleanup) { getExec().scheduleAtFixedRate(new CleanupTask(), period, period, TimeUnit.SECONDS); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCache " + name + " cleanup every " + period + " secs"); } if (trackAll) track = new ConcurrentHashMap<>(5000); }
schedule(new CleanupTask(), 100); // immediate cleanup in 100 msec
exec.schedule(new CleanupTask(), 100, TimeUnit.MILLISECONDS); // immediate cleanup in 100 msec if (debugCleanup) System.out.println("CleanupTask scheduled due to soft limit time=" + new Date());
getExec().schedule(new CleanupTask(), 100, TimeUnit.MILLISECONDS); // immediate cleanup in 100 msec if (debugCleanup) System.out.println("CleanupTask scheduled due to soft limit time=" + new Date());
/** * 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 FileCache(String name, int minElementsInMemory, int softLimit, int hardLimit, int period) { this.name = name; this.minElements = minElementsInMemory; this.softLimit = softLimit; this.hardLimit = hardLimit; this.period = (long) 1000 * period; cache = new ConcurrentHashMap<>(2 * softLimit, 0.75f, 8); files = new ConcurrentHashMap<>(4 * softLimit, 0.75f, 8); boolean wantsCleanup = period > 0; if (wantsCleanup) { scheduleAtFixedRate(new CleanupTask(), this.period, this.period); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCache " + name + " cleanup every " + period + " secs"); } 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 FileCache(String name, int minElementsInMemory, int softLimit, int hardLimit, int period) { this.name = name; this.minElements = minElementsInMemory; this.softLimit = softLimit; this.hardLimit = hardLimit; cache = new ConcurrentHashMap<Object, CacheElement>(2 * softLimit, 0.75f, 8); files = new ConcurrentHashMap<FileCacheable, CacheElement.CacheFile>(4 * softLimit, 0.75f, 8); if (period > 0) { if (exec == null) exec = Executors.newSingleThreadScheduledExecutor(); exec.scheduleAtFixedRate(new CleanupTask(), period, period, TimeUnit.SECONDS); cacheLog.debug("FileCache " + name + " cleanup every " + period + " secs"); } }