Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-8319

Restore mechanism to manipulate Weigher implementation used by Caffeine

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 9.1.0.Final
    • Eviction
    • 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;
      }
      

              wburns@redhat.com Will Burns
              pferraro@redhat.com Paul Ferraro
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: