]
William Burns commented on ISPN-8319:
-------------------------------------
Talking with Paul, it seems the underlying use case is to have an entry that is not part
of the eviction processing ensuring it will always stay in the cache until the user
removes it (or expiration).
Restore mechanism to manipulate Weigher implementation used by
Caffeine
-----------------------------------------------------------------------
Key: ISPN-8319
URL:
https://issues.jboss.org/browse/ISPN-8319
Project: Infinispan
Issue Type: Enhancement
Components: Eviction
Affects Versions: 9.1.0.Final
Reporter: Paul Ferraro
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.
{code:java}
public interface EntrySizeCalculatorProvider {
<K, V> EntrySizeCalculator<K, V> getEntrySizeCalculator();
}
{code}
MemoryConfigurationBuilder.java:
{code:java}
public MemoryConfigurationBuilder.entrySizeCalculatorProvider(EntrySizeCalculatorProvider
provider) {
// ...
}
{code}
Additionally, we can reinterpret EvictionType as a specific EntrySizeCalculatorProvider
implementation.
e.g. MemoryConfigurationBuilder.java:
{code: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;
}
{code}