OffHeapCache extends AbstractSearchableCache<K, V> { public V get(K key) { final Pointer pointer = pointerMap.get(key); if (pointer != null) { readLock(key); try { stats.incrementHitCount(); final byte[] payload = bufferStore.retrieve(pointer); return serializer.deserialize(payload); } finally { readUnlock(key); } } else { stats.incrementMissCount(); final V value = cacheLoader.load(key); if (value != null) { stats.incrementLoadCount(); put(key, value); } return value; } } OffHeapCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      final IndexHandler<K, V> indexHandler, final OffHeapByteBufferStore byteBufferStore,
      final Serializer<V> serializer,
      final long bufferCleanerPeriod, final float bufferCleanerThreshold,
      final int concurrencyLevel,
      final long evictionPeriod); void put(K key, V value); @Override void put(final K key, final V value, final TimeUnit timeUnit, final long duration); V get(K key); V invalidate(K key); boolean contains(K key); void clear(); @Override long size(); @Override CacheStats stats(); static final long DEFAULT_BUFFER_CLEANER_PERIOD; static final long DEFAULT_EVICTION_PERIOD; static final float DEFAULT_BUFFER_CLEANER_THRESHOLD; static final int DEFAULT_CONCURRENCY_LEVEL; }
@Test public void getLoadsData() { doReturn("d").when(cacheLoader).load("c"); assertEquals(cache.get("c"), "d"); verify(indexHandler).add("c", "d"); }