[infinispan-issues] [JBoss JIRA] (ISPN-8319) Restore mechanism to manipulate Weigher implementation used by Caffeine

Paul Ferraro (JIRA) issues at jboss.org
Wed Sep 20 15:06:00 EDT 2017


    [ https://issues.jboss.org/browse/ISPN-8319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13466508#comment-13466508 ] 

Paul Ferraro commented on ISPN-8319:
------------------------------------

... or manually evicts it (via Cache.evict(...)).

> 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}



--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the infinispan-issues mailing list