Class CacheBase

  • All Implemented Interfaces:
    com.sap.cloud.mobile.foundation.cache.Cache

    
    public abstract class CacheBase<K, V>
     implements Cache<K, V>
                        

    Abstract class for Cache implementations.

    Provides default implementation of Cache:
    1. Embeds and handles the Android Context and cache capacity (maximum number of entries) via
       init or init.
    2. Forces concrete Cache implementation to enforce operation state via
       checkConfiguration in cache read-write access methods.
    3. Provides no-op(not supported) cache methods.
    
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Constructor Summary

      Constructors 
      Constructor Description
      CacheBase()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      Context getContext() Returns the Android application context.
      int getMaxEntries() Returns the cache capacity specified via init.
      void init(@NonNull() Context context, int maxEntries) Initializes a cache with Android application context and maximum number of entries the cache can hold.
      void init(@NonNull() Context context) Initializes a cache with Android application context.
      V put(@NonNull() K key, @NonNull() V value, double cost) Adds the value and the associated cost to the cache for the key.
      V put(@NonNull() K key, @NonNull() V value) Adds or updates a value associated with a key.
      V get(@NonNull() K key) Returns the value associated with a key.
      CacheEntry getEntry(@NonNull() K key) Retrieves the value associated with a key, then returns a CacheEntry object that embeds the key and value.
      double getCostOfEntries() Returns the aggregated value of the cost of the entries in the cache.
      int getEntryCount() Returns the number of entries (key-value pairs) in the cache.
      List<K> keys() Returns a list of keys of all entries in the cache or a non-null empty list.
      void remove(@NonNull() K key) Removes a cache entry.
      void removeAll() Removes all entries from the cache.
      • Methods inherited from class java.lang.Object

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

      • CacheBase

        CacheBase()
    • Method Detail

      • getContext

        @NonNull() Context getContext()

        Returns the Android application context.

      • init

         void init(@NonNull() Context context, int maxEntries)

        Initializes a cache with Android application context and maximum number of entries the cache can hold.

        Parameters:
        context - Android application context
        maxEntries - maximum number of entries the cache can hold.
      • init

         void init(@NonNull() Context context)

        Initializes a cache with Android application context.

        Parameters:
        context - Android application context
      • put

        @Nullable() V put(@NonNull() K key, @NonNull() V value, double cost)

        Adds the value and the associated cost to the cache for the key. The behavior when the aggregate of costs exceeds the maximum cost during the execution of this method is implementation dependent.

        Parameters:
        key - a non-null key of a cache entry
        value - a non-null value to add
        cost - the cost associated with this entry.
      • put

        @Nullable() V put(@NonNull() K key, @NonNull() V value)

        Adds or updates a value associated with a key.

        Parameters:
        key - a non-null key of a cache entry
        value - a non-null value to add
      • get

        @Nullable() V get(@NonNull() K key)

        Returns the value associated with a key.

        Parameters:
        key - a non-null key of a cache entry
      • getEntry

        @Nullable() CacheEntry getEntry(@NonNull() K key)

        Retrieves the value associated with a key, then returns a CacheEntry object that embeds the key and value.

        Parameters:
        key - a non-null key of a cache entry
      • getCostOfEntries

         double getCostOfEntries()

        Returns the aggregated value of the cost of the entries in the cache. The concrete behavior is implementation dependent.

      • getEntryCount

         int getEntryCount()

        Returns the number of entries (key-value pairs) in the cache.

      • keys

        @NonNull() List<K> keys()

        Returns a list of keys of all entries in the cache or a non-null empty list. The order of the entries in the list is implementation dependent.

      • remove

         void remove(@NonNull() K key)

        Removes a cache entry.

        Parameters:
        key - a non-null key of the entry to remove
      • removeAll

         void removeAll()

        Removes all entries from the cache.