Class JCache<K,V>

java.lang.Object
org.redisson.RedissonObject
org.redisson.jcache.JCache<K,V>
Type Parameters:
K - key
V - value
All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<javax.cache.Cache.Entry<K,V>>, javax.cache.Cache<K,V>, CacheAsync<K,V>, RObject, RObjectAsync

public class JCache<K,V> extends RedissonObject implements javax.cache.Cache<K,V>, CacheAsync<K,V>
JCache implementation
Author:
Nikita Koksharov
  • Constructor Details

  • Method Details

    • get

      public V get(K key)
      Specified by:
      get in interface javax.cache.Cache<K,V>
    • getAsync

      public RFuture<V> getAsync(K key)
      Description copied from interface: CacheAsync
      This method retrieves an entry from the cache. If the cache uses the read-through pattern, and the method would return null because the entry is not present in the cache, then the cache's CacheLoader will try to load the entry.
      Specified by:
      getAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key whose value should be returned
      Returns:
      the element, or null if the entry does not exist.
    • getAll

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

      public RFuture<Map<K,V>> getAllAsync(Set<? extends K> keys)
      Description copied from interface: CacheAsync
      This method accepts a set of requested keys and retrieves a collection of entries from the CacheAsync, returning them as a Map of the associated values. If the cache uses the read-through pattern, and the method would return null for a key because an entry is not present in the cache, the Cache's CacheLoader will try to load the entry. If a key's entry cannot be loaded, the key will not appear in the Map.
      Specified by:
      getAllAsync in interface CacheAsync<K,V>
      Parameters:
      keys - The keys whose values should be returned.
      Returns:
      A Map of entries associated with the given keys. If a key is not found in the cache, it will not be in the Map.
    • containsKey

      public boolean containsKey(K key)
      Specified by:
      containsKey in interface javax.cache.Cache<K,V>
    • containsKeyAsync

      public RFuture<Boolean> containsKeyAsync(K key)
      Description copied from interface: CacheAsync
      This method returns a Boolean true/false value, depending on whether the CacheAsync has a mapping for a key k such that key.equals(k).
      Specified by:
      containsKeyAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key with a possible mapping in the cache.
      Returns:
      true if such a mapping exists
    • loadAll

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

      public RFuture<Void> putAsync(K key, V value)
      Description copied from interface: CacheAsync
      This method places the given value V in the cache and associates it with the given key K. If the CacheAsync already has a mapping for the key, the previous value is replaced by the given value V. This occurs if and only if c.containsKey(k) would return true.)
      Specified by:
      putAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key to place in the cache
      value - the value to associate with the given key
      Returns:
      void
    • put

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

      public V getAndPut(K key, V value)
      Specified by:
      getAndPut in interface javax.cache.Cache<K,V>
    • getAndPutAsync

      public RFuture<V> getAndPutAsync(K key, V value)
      Description copied from interface: CacheAsync
      This method places the given key and value in the cache. Any value already in the cache is returned and replaced by the new given value. This occurs if and only if c.containsKey(k) would return true.) If there was no value already in the cache, the method returns null.
      Specified by:
      getAndPutAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key to place in the cache
      value - the value to associate with the given key
      Returns:
      the previous value in the cache, or null if none already existed
    • putAll

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

      public RFuture<Void> putAllAsync(Map<? extends K,? extends V> map)
      Description copied from interface: CacheAsync
      This method copies all of the entries from the given Map to the CacheAsync. This method is equivalent to calling CacheAsync.putAsync(Object, Object) on this cache one time for each mapping from key k to value v in the given Map. Individual puts may occur in any order. If entries in the cache corresponding to entries in the Map, or the Map itself, is changed or removed during this operation, then the behavior of this method is not defined. If default consistency mode is enabled, then each put is atomic but not the entire putAll operation. Listeners can observe individual updates.
      Specified by:
      putAllAsync in interface CacheAsync<K,V>
      Parameters:
      map - the Map that contains the entries to be copied to the cache
      Returns:
      void
    • putIfAbsent

      public boolean putIfAbsent(K key, V value)
      Specified by:
      putIfAbsent in interface javax.cache.Cache<K,V>
    • putIfAbsentAsync

      public RFuture<Boolean> putIfAbsentAsync(K key, V value)
      Description copied from interface: CacheAsync
      This method places the given key and value in the cache atomically, if the key is not already associated with a value in the cache.
      Specified by:
      putIfAbsentAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key to place in the cache
      value - the value to associate with the given key
      Returns:
      true if the value was successfully placed in the cache
    • remove

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

      public RFuture<Boolean> removeAsync(K key)
      Description copied from interface: CacheAsync
      This method deletes the mapping for a given key from the cache, if it is present. This occurs if and only if there is a mapping from key k to value v such that (key==null ? k==null : key.equals(k)). This method returns true if the removal was successful, or false if there was no such mapping.
      Specified by:
      removeAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key whose mapping will be deleted
      Returns:
      returns true if successful, or false if there was no mapping
    • remove

      public boolean remove(K key, V value)
      Specified by:
      remove in interface javax.cache.Cache<K,V>
    • removeAsync

      public RFuture<Boolean> removeAsync(K key, V value)
      Description copied from interface: CacheAsync
      This method atomically removes a key's mapping only if it is currently mapped to the provided value.
      Specified by:
      removeAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key whose mapping will be deleted
      value - the value that should be mapped to the given key
      Returns:
      returns true if successful, or false if there was no such mapping
    • getAndRemove

      public V getAndRemove(K key)
      Specified by:
      getAndRemove in interface javax.cache.Cache<K,V>
    • getAndRemoveAsync

      public RFuture<V> getAndRemoveAsync(K key)
      Description copied from interface: CacheAsync
      This method atomically removes the entry for a key only if it is currently mapped to some value.
      Specified by:
      getAndRemoveAsync in interface CacheAsync<K,V>
      Parameters:
      key - the given key
      Returns:
      the value if it existed, or null if it did not
    • replace

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

      public RFuture<Boolean> replaceAsync(K key, V oldValue, V newValue)
      Description copied from interface: CacheAsync
      This method atomically replaces an entry only if the key is currently mapped to a given value.
      Specified by:
      replaceAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key associated with the given oldValue
      oldValue - the value that should be associated with the key
      newValue - the value that will be associated with the key
      Returns:
      true if the value was replaced, or false if not
    • replace

      public boolean replace(K key, V value)
      Specified by:
      replace in interface javax.cache.Cache<K,V>
    • replaceAsync

      public RFuture<Boolean> replaceAsync(K key, V value)
      Description copied from interface: CacheAsync
      This method atomically replaces an entry only if the key is currently mapped to some value.
      Specified by:
      replaceAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key mapped to the given value
      value - the value mapped to the given key
      Returns:
      true if the value was replaced, or false if not
    • getAndReplace

      public V getAndReplace(K key, V value)
      Specified by:
      getAndReplace in interface javax.cache.Cache<K,V>
    • getAndReplaceAsync

      public RFuture<V> getAndReplaceAsync(K key, V value)
      Description copied from interface: CacheAsync
      This method atomically replaces a given key's value if and only if the key is currently mapped to a value.
      Specified by:
      getAndReplaceAsync in interface CacheAsync<K,V>
      Parameters:
      key - the key associated with the given value
      value - the value associated with the given key
      Returns:
      the previous value mapped to the given key, or null if there was no such mapping.
    • removeAll

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

      public RFuture<Void> removeAllAsync(Set<? extends K> keys)
      Description copied from interface: CacheAsync
      This method deletes the entries for the given keys. The order in which the individual entries are removed is undefined. For every entry in the key set, the following are called: • any registered CacheEntryRemovedListeners • if the cache is a write-through cache, the CacheWriter If the key set is empty, the CacheWriter is not called.
      Specified by:
      removeAllAsync in interface CacheAsync<K,V>
      Parameters:
      keys - the keys to remove
      Returns:
      void
    • removeAll

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

      public void clear()
      Specified by:
      clear in interface javax.cache.Cache<K,V>
    • clearAsync

      public RFuture<Void> clearAsync()
      Description copied from interface: CacheAsync
      This method empties the cache's contents, without notifying listeners or CacheWriters.
      Specified by:
      clearAsync in interface CacheAsync<K,V>
      Returns:
      void
    • getConfiguration

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

      public <T> T invoke(K key, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... arguments) throws javax.cache.processor.EntryProcessorException
      Specified by:
      invoke in interface javax.cache.Cache<K,V>
      Throws:
      javax.cache.processor.EntryProcessorException
    • invokeAll

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

      public javax.cache.CacheManager getCacheManager()
      Specified by:
      getCacheManager in interface javax.cache.Cache<K,V>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface javax.cache.Cache<K,V>
      Specified by:
      close in interface Closeable
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface javax.cache.Cache<K,V>
    • unwrap

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

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

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

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