OffHeapCacheBuilder extends BaseCacheBuilder { @SuppressWarnings("unchecked") public <K, V> OffHeapCache<K, V> build() { if (this.byteBufferStore == null) { throw new NecessaryArgumentException("ByteBufferStore must be set!"); } return new OffHeapCache<>(name, (CacheLoader<K, V>) cacheLoader, (EvictionListener<K, V>) evictionListener, (IndexHandler<K, V>) indexHandler, byteBufferStore, (Serializer<V>) serializer, bufferCleanerPeriod, bufferCleanerThreshold, concurrencyLevel, evictionPeriod); } OffHeapCacheBuilder(); OffHeapCacheBuilder storage(final OffHeapByteBufferStore bufferStore); @SuppressWarnings("unchecked") OffHeapCacheBuilder serializer(final Serializer<V> serializer); @SuppressWarnings("unchecked") OffHeapCacheBuilder cacheLoader(final CacheLoader<K, V> cacheLoader); OffHeapCacheBuilder name(final String name); @SuppressWarnings("unchecked") OffHeapCacheBuilder evictionListener(
      final EvictionListener<K, V> evictionListener); @SuppressWarnings("unchecked") OffHeapCacheBuilder indexHandler(final IndexHandler<K, V> indexHandler); OffHeapCacheBuilder concurrencyLevel(final int concurrencyLevel); OffHeapCacheBuilder evictionPeriod(final long evictionPeriod); OffHeapCacheBuilder bufferCleanerPeriod(final long bufferCleanerPeriod); OffHeapCacheBuilder bufferCleanerThreshold(float bufferCleanerThreshold); synchronized OffHeapCacheBuilder addIndex(final String attributeName,
      final IndexType indexType); @SuppressWarnings("unchecked") OffHeapCache<K, V> build(); @SuppressWarnings("unchecked") OffHeapCache<K, V> build(final String name);  }
@Test public void build() { OffHeapByteBufferStore bufferStore = new OffHeapByteBufferStore(8388608, 10); Cache<Object, Object> cache = CacheBuilder.offHeapCache() .storage(bufferStore) .cacheLoader(BaseCacheBuilder.DEFAULT_CACHE_LOADER) .evictionListener(BaseCacheBuilder.DEFAULT_EVICTION_LISTENER) .indexHandler(DummyIndexHandler.getInstance()) .addIndex("age", IndexType.RANGE_INDEX) .serializer(BaseCacheBuilder.DEFAULT_SERIALIZER) .bufferCleanerPeriod(100).bufferCleanerThreshold(0.6f).concurrencyLevel(10) .evictionPeriod(100).build(); assertTrue(cache instanceof SearchableCache); assertTrue(cache instanceof OffHeapCache); }
@Test(expected = NecessaryArgumentException.class) public void buildThrowsNecessaryArgumentException() { CacheBuilder.offHeapCache().build("my-cache"); }