-
Enhancement
-
Resolution: Unresolved
-
Major
-
None
-
9.1.0.Final
-
None
Infinispan 9.1 allows a user to manipulate the Weigher implementation used by Caffeine to by configuring a cache with a custom DataContainer that uses a specific EntrySizeCalculator implementation. However, the DataContainerConfiguration object is deprecated, suggesting that a future release will no longer expose a mechanism for doing this. Such a mechanism is necessary to allow users to exempt specific cache entries (while allowing others) from eviction.
One proposal is to allow users to specify an EntrySizeCalculator via the MemoryConfigurationBuilder.
e.g.
public interface EntrySizeCalculatorProvider { <K, V> EntrySizeCalculator<K, V> getEntrySizeCalculator(); }
MemoryConfigurationBuilder.java:
public MemoryConfigurationBuilder.entrySizeCalculatorProvider(EntrySizeCalculatorProvider provider) { // ... }
Additionally, we can reinterpret EvictionType as a specific EntrySizeCalculatorProvider implementation.
e.g. MemoryConfigurationBuilder.java:
private static final Map<EvictionType, EntrySizeCalculatorProvider> PROVIDERS = new EnumMap<>(EvictionType.class); static { PROVIDERS.put(EvictionType.COUNT, new EntrySizeCalculatorProvider() { public <K, V> EntrySizeCalculator<K, V> getEntrySizeCalculator() { return (key, value) -> 1L; } }); PROVIDERS.put(EvictionType.MEMORY, new EntrySizeCalculatorProvider() { public <K, V> EntrySizeCalculator<K, V> getEntrySizeCalculator() { return new WrappedByteArraySizeCalculator<>(new PrimitiveEntrySizeCalculator()); } }); } MemoryConfigurationBuilder evictionType(EvictionType type) { this.entrySizeCalculatorProvider(PROVIDERS.get(type)); return this; }