Class CacheProxy<K,V>

java.lang.Object
com.github.benmanes.caffeine.jcache.CacheProxy<K,V>
All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<Cache.Entry<K,V>>, Cache<K,V>
Direct Known Subclasses:
LoadingCacheProxy

public class CacheProxy<K,V> extends Object implements Cache<K,V>
An implementation of JSR-107 Cache backed by a Caffeine cache.
  • Field Details

  • Constructor Details

  • Method Details

    • containsKey

      public boolean containsKey(K key)
      Specified by:
      containsKey in interface Cache<K,V>
    • get

      public @Nullable V get(K key)
      Specified by:
      get in interface Cache<K,V>
    • getAll

      public Map<K,V> getAll(Set<? extends K> keys)
      Specified by:
      getAll in interface Cache<K,V>
    • getAndFilterExpiredEntries

      protected Map<K, Expirable<V>> getAndFilterExpiredEntries(Set<? extends K> keys, boolean updateAccessTime)
      Returns all of the mappings present, expiring as required, and optionally updates their access expiry time.
    • loadAll

      public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener)
      Specified by:
      loadAll in interface Cache<K,V>
    • put

      public void put(K key, V value)
      Specified by:
      put in interface Cache<K,V>
    • getAndPut

      public @Nullable V getAndPut(K key, V value)
      Specified by:
      getAndPut in interface Cache<K,V>
    • putNoCopyOrAwait

      @CanIgnoreReturnValue protected CacheProxy.PutResult<V> putNoCopyOrAwait(K key, V value, boolean publishToWriter)
      Associates the specified value with the specified key in the cache.
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      publishToWriter - if the writer should be notified
      Returns:
      the old value
    • putAll

      public void putAll(Map<? extends K, ? extends V> map)
      Specified by:
      putAll in interface Cache<K,V>
    • putIfAbsent

      public boolean putIfAbsent(K key, V value)
      Specified by:
      putIfAbsent in interface Cache<K,V>
    • remove

      public boolean remove(K key)
      Specified by:
      remove in interface Cache<K,V>
    • remove

      @CanIgnoreReturnValue public boolean remove(K key, V oldValue)
      Specified by:
      remove in interface Cache<K,V>
    • getAndRemove

      public V getAndRemove(K key)
      Specified by:
      getAndRemove in interface Cache<K,V>
    • replace

      public boolean replace(K key, V oldValue, V newValue)
      Specified by:
      replace in interface Cache<K,V>
    • replace

      public boolean replace(K key, V value)
      Specified by:
      replace in interface Cache<K,V>
    • getAndReplace

      public V getAndReplace(K key, V value)
      Specified by:
      getAndReplace in interface Cache<K,V>
    • removeAll

      public void removeAll(Set<? extends K> keys)
      Specified by:
      removeAll in interface Cache<K,V>
    • removeAll

      public void removeAll()
      Specified by:
      removeAll in interface Cache<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Cache<K,V>
    • getConfiguration

      public <C extends Configuration<K,V>> C getConfiguration(Class<C> clazz)
      Specified by:
      getConfiguration in interface Cache<K,V>
    • invoke

      public <T> @Nullable T invoke(K key, EntryProcessor<K,V,T> entryProcessor, Object... arguments)
      Specified by:
      invoke in interface Cache<K,V>
    • invokeAll

      public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, EntryProcessor<K,V,T> entryProcessor, Object... arguments)
      Specified by:
      invokeAll in interface Cache<K,V>
    • getName

      public String getName()
      Specified by:
      getName in interface Cache<K,V>
    • getCacheManager

      public CacheManager getCacheManager()
      Specified by:
      getCacheManager in interface Cache<K,V>
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface Cache<K,V>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Cache<K,V>
      Specified by:
      close in interface Closeable
    • unwrap

      public <T> T unwrap(Class<T> clazz)
      Specified by:
      unwrap in interface Cache<K,V>
    • registerCacheEntryListener

      public void registerCacheEntryListener(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)
      Specified by:
      registerCacheEntryListener in interface Cache<K,V>
    • deregisterCacheEntryListener

      public void deregisterCacheEntryListener(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)
      Specified by:
      deregisterCacheEntryListener in interface Cache<K,V>
    • iterator

      public Iterator<Cache.Entry<K,V>> iterator()
      Specified by:
      iterator in interface Cache<K,V>
      Specified by:
      iterator in interface Iterable<K>
    • requireNotClosed

      protected final void requireNotClosed()
      Checks that the cache is not closed.
    • copyOf

      protected final <T> T copyOf(@Nullable T object)
      Returns a copy of the value if value-based caching is enabled.
      Type Parameters:
      T - the type of object being copied
      Parameters:
      object - the object to be copied
      Returns:
      a copy of the object if storing by value or the same instance if by reference
    • copyValue

      protected final V copyValue(@Nullable Expirable<V> expirable)
      Returns a copy of the value if value-based caching is enabled.
      Parameters:
      expirable - the expirable value to be copied
      Returns:
      a copy of the value if storing by value or the same instance if by reference
    • copyMap

      protected final Map<K,V> copyMap(Map<K, Expirable<V>> map)
      Returns a deep copy of the map if value-based caching is enabled.
      Parameters:
      map - the mapping of keys to expirable values
      Returns:
      a deep or shallow copy of the mappings depending on the store by value setting
    • currentTimeMillis

      protected final long currentTimeMillis()
      Returns the current time in milliseconds.
    • nanosToMillis

      protected static long nanosToMillis(long nanos)
      Returns the nanosecond time in milliseconds.
    • setAccessExpireTime

      protected final void setAccessExpireTime(K key, Expirable<?> expirable, long currentTimeMillis)
      Sets the access expiration time.
      Parameters:
      key - the entry's key
      expirable - the entry that was operated on
      currentTimeMillis - the current time, or 0 if not read yet
    • getWriteExpireTimeMillis

      protected final long getWriteExpireTimeMillis(boolean created)
      Returns the time when the entry will expire.
      Parameters:
      created - if the write operation is an insert or an update
      Returns:
      the time when the entry will expire, zero if it should expire immediately, Long.MIN_VALUE if it should not be changed, or Long.MAX_VALUE if eternal