Class BaseCacheService<K,V>

java.lang.Object
com.helixframework.cache.BaseCacheService<K,V>
All Implemented Interfaces:
CacheService<K,V>

public abstract class BaseCacheService<K,V> extends Object implements CacheService<K,V>
  • Constructor Summary

    Constructors
    Constructor
    Description
    BaseCacheService(io.micrometer.core.instrument.MeterRegistry meterRegistry)
     
     
    BaseCacheService(String name, io.micrometer.core.instrument.MeterRegistry meterRegistry)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all entries from the cache.
    protected abstract void
     
    protected abstract void
    doEvict(K key)
     
    protected abstract Optional<V>
    doGet(K key)
     
    protected abstract void
    doPut(K key, V value)
     
    protected abstract void
    doPut(K key, V value, Duration duration)
     
    void
    evict(K key)
    Removes the cache entry associated with the specified key.
    get(K key)
    Retrieves the value associated with the specified key from the cache, if present.
    Generates a formatted name for the class by splitting its simple name at camel case boundaries and joining the segments with underscores, then converting the resulting string to lowercase.
    void
    put(K key, V value)
    Stores a key-value pair in the cache.
    void
    put(K key, V value, Duration ttl)
    Stores a key-value pair in the cache with an optional time-to-live (TTL) duration.

    Methods inherited from class java.lang.Object

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

    • BaseCacheService

      public BaseCacheService(String name)
    • BaseCacheService

      public BaseCacheService(io.micrometer.core.instrument.MeterRegistry meterRegistry)
    • BaseCacheService

      public BaseCacheService(String name, io.micrometer.core.instrument.MeterRegistry meterRegistry)
  • Method Details

    • get

      public Optional<V> get(K key)
      Description copied from interface: CacheService
      Retrieves the value associated with the specified key from the cache, if present.
      Specified by:
      get in interface CacheService<K,V>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      an Optional containing the value associated with the specified key, or an empty Optional if the key is not present in the cache
    • put

      public void put(K key, V value)
      Description copied from interface: CacheService
      Stores a key-value pair in the cache. If the key already exists, the associated value is replaced with the new value.
      Specified by:
      put in interface CacheService<K,V>
      Parameters:
      key - the key with which the specified value is to be associated; must not be null
      value - the value to be associated with the specified key; may be null
    • put

      public void put(K key, V value, Duration ttl)
      Description copied from interface: CacheService
      Stores a key-value pair in the cache with an optional time-to-live (TTL) duration. If the key already exists, the associated value is replaced with the new value, and the TTL is updated. The TTL specifies the duration for which the entry remains in the cache.
      Specified by:
      put in interface CacheService<K,V>
      Parameters:
      key - the key with which the specified value is to be associated; must not be null
      value - the value to be associated with the specified key; may be null
      ttl - the time-to-live duration for the cache entry; must not be null
    • evict

      public void evict(K key)
      Description copied from interface: CacheService
      Removes the cache entry associated with the specified key. If the key does not exist in the cache, no action is taken.
      Specified by:
      evict in interface CacheService<K,V>
      Parameters:
      key - the key of the cache entry to be removed; must not be null
    • clear

      public void clear()
      Description copied from interface: CacheService
      Removes all entries from the cache. After this operation, the cache will be empty.
      Specified by:
      clear in interface CacheService<K,V>
    • getName

      public String getName()
      Description copied from interface: CacheService
      Generates a formatted name for the class by splitting its simple name at camel case boundaries and joining the segments with underscores, then converting the resulting string to lowercase.
      Specified by:
      getName in interface CacheService<K,V>
      Returns:
      the formatted name of the class
    • doGet

      protected abstract Optional<V> doGet(K key)
    • doPut

      protected abstract void doPut(K key, V value)
    • doPut

      protected abstract void doPut(K key, V value, Duration duration)
    • doEvict

      protected abstract void doEvict(K key)
    • doClear

      protected abstract void doClear()