com.atlassian.cache
Interface Cache<K,V>


@PublicApi
public interface Cache<K,V>


Method Summary
 boolean containsKey(K key)
          Returns whether an entry exists in the cache under the specified key.
 V get(K key)
          Retrieve an object from this cache.
 Collection<K> getKeys()
          Gets the keys of all objects currently stored in the cache.
 String getName()
          The name of the cache, uniquely identifies this cache.
 void put(K key, V value)
          Put an object into the cache.
 V putIfAbsent(K key, V value)
          Atomically associates the specified key with the given value if it is not already associated with a value.
 void remove(K key)
          Remove the object identified by the key from the cache.
 boolean remove(K key, V value)
          Atomically removes the entry for a key only if currently mapped to a given value.
 void removeAll()
          Remove all of the objects from this cache.
 boolean replace(K key, V oldValue, V newValue)
          Atomically replaces the entry for a key only if currently mapped to a given value.
 

Method Detail

getName

String getName()
The name of the cache, uniquely identifies this cache.

Returns:
the name of the cache.

containsKey

boolean containsKey(@NotNull
                    K key)
Returns whether an entry exists in the cache under the specified key.

Note that:

Parameters:
key - the key for the entry to check for containment.
Returns:
true iff the cache already contains an entry under the specified key.
Since:
2.2.0

getKeys

Collection<K> getKeys()
Gets the keys of all objects currently stored in the cache. This will return the keys in a new collection.

Returns:
a collection of Objects keys.

get

V get(@NotNull
      K key)
Retrieve an object from this cache.

Parameters:
key - uniquely identifying the object to be retrieved.
Returns:
the object from the cache, or null if the object is not found.

put

void put(@NotNull
         K key,
         V value)
Put an object into the cache. If the specified key already exists within the cache, it will be replaced by the new object.

NOTE: Users of caches that wish to be well behaved in a clustered environment should use the CacheLoader semantics and supply a CacheLoader when getting the Cache.

Parameters:
key - uniquely identifying the object to be added into the cache.
value - to be cached.

remove

void remove(@NotNull
            K key)
Remove the object identified by the key from the cache. If no object can be found associated with this key then no action is taken.

Parameters:
key - uniquely identifying the object to be removed.

removeAll

void removeAll()
Remove all of the objects from this cache.


putIfAbsent

V putIfAbsent(K key,
              V value)
Atomically associates the specified key with the given value if it is not already associated with a value.

Parameters:
key -
value -
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key.

replace

boolean replace(K key,
                V oldValue,
                V newValue)
Atomically replaces the entry for a key only if currently mapped to a given value.

Parameters:
key - key with which the specified value is associated
oldValue - value expected to be associated with the specified key
newValue - value to be associated with the specified key
Returns:
true if the value was replaced, false otherwise

remove

boolean remove(K key,
               V value)
Atomically removes the entry for a key only if currently mapped to a given value.

Parameters:
key - key with which the specified value is associated
value - value expected to be associated with the specified key
Returns:
true if the value was removed, false otherwise


Copyright © 2014 Atlassian. All Rights Reserved.