public static byte[] retrieve(String key) { Pointer ptr = get(key); if (ptr == null) return null; if (ptr.expired() || ptr.free) { map.remove(key); if (!ptr.free) { MemoryManager.free(ptr); } return null; } else { return MemoryManager.retrieve(ptr); } }
public static void init( int numberOfBuffers, int size, int initialCapacity, int concurrencyLevel) { map = new MapMaker() .concurrencyLevel(concurrencyLevel) .initialCapacity(initialCapacity) .makeMap(); logger.info("*** initializing *******************************\r\n" + Format.logo()); logger.info("************************************************"); MemoryManager.init(numberOfBuffers, size); logger.info("initialized"); logger.info( Format.it("number of buffer(s): \t%1d with %2s each", numberOfBuffers, Ram.inMb(size))); logger.info(Format.it("initial capacity: \t%1d", initialCapacity)); logger.info(Format.it("concurrency level: \t%1d", concurrencyLevel)); }
public static void collectLFU() { MemoryManager.collectLFU(); }
public static void collectExpired() { MemoryManager.collectExpired(); }
public static void free(String key) { Pointer p = map.remove(key); if (p != null) { MemoryManager.free(p); } }
public static Pointer update(String key, byte[] payload) { Pointer p = map.get(key); p = MemoryManager.update(p, payload); return p; }
public static Pointer put(String key, byte[] payload, int expiresIn) { return map.put(key, MemoryManager.store(payload, expiresIn)); }
public static void clear() { map.clear(); MemoryManager.clear(); logger.info("Cache cleared"); }