Interface CacheCostFactor

  • All Implemented Interfaces:

    
    public interface CacheCostFactor<K>
    
                        

    In parallel to the Cache Replacement Policy, the optional Cost Factor feature described here provides the eviction mechanism for a Cache implementation to remove one or more existing cache entries so that a new item can be added (via put) when the aggregated cost exceeds the maximum total cost:

    • During cache initialization, the cache implementation should have method(s) to let the user specify the maximum total cost, and a CacheCostFactor instance that implements onExceedMaxCost.
    • When the put is called:

    Note that the Cost Factor can also be used as a mechanism to pin down a certain entry that is deemed important regardless of the Cache Replacement Policy.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract List<K> onExceedMaxCost(@NonNull() List<K> existingKeys) This method is invoked during put to instruct the cache implementation to remove one or more cache items from a list of existing keys so that a new cache item can be added when the aggregated costs exceeds the maximum cost.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • onExceedMaxCost

        @NonNull() abstract List<K> onExceedMaxCost(@NonNull() List<K> existingKeys)

        This method is invoked during put to instruct the cache implementation to remove one or more cache items from a list of existing keys so that a new cache item can be added when the aggregated costs exceeds the maximum cost.

        • The cache will remove the entry/entries based on the returned list.
        • The current put will proceed and the entry will be added successfully.
        Parameters:
        existingKeys - a list of keys associated with existing cache entries sorted in cost ascending order