org.omnaest.utils.cache
Interface Cache<K,V>

Type Parameters:
K -
V -
All Superinterfaces:
Map<K,V>, Serializable
All Known Implementing Classes:
ConcurrentWeakReferenceCache, MapToCacheAdapter, SynchronizedWeakReferenceCache

public interface Cache<K,V>
extends Map<K,V>, Serializable

A Cache is a container which allows to hold key value pairs. The makes it technically very similar to a Map so it does actually implements the Map interface.

Nevertheless a Map is more general than a Cache. A Cache has more a focus on the lifecycle of a stored element. So some Cache implementations will e.g. clear elements from its store, which are not requested for a given amount of time.

Do to the possibly fast clearing of elements the keySet(), values() and entrySet() returned are unmodifiable and represent only a snapshot of the Cache state when the function call was made. The returned Collections are not updated when the Cache content changes.

Note: this Cache represents a lightweight contract which is intended to be easily implementable. If a more feature rich cache contract is needed take a look at com.google.common.cache.Cache.

Author:
Omnaest
See Also:
CacheUtils

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 Set<Map.Entry<K,V>> entrySet()
          Returns an unmodifiable Set of all Map.Entrys within the Cache which only represents a snapshot in moment
 V getOrCreate(K key, Factory<V> factory)
          Gets a cached value or creates a new one using the given Factory and puts the new value into the cache.
 Set<K> keySet()
          Returns an unmodifiable Set of all keys within the Cache which only represents a snapshot in moment
 Collection<V> values()
          Returns an unmodifiable Collection of all values within the Cache which only represents a snapshot in moment
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size
 

Method Detail

keySet

Set<K> keySet()
Returns an unmodifiable Set of all keys within the Cache which only represents a snapshot in moment

Specified by:
keySet in interface Map<K,V>

values

Collection<V> values()
Returns an unmodifiable Collection of all values within the Cache which only represents a snapshot in moment

Specified by:
values in interface Map<K,V>

entrySet

Set<Map.Entry<K,V>> entrySet()
Returns an unmodifiable Set of all Map.Entrys within the Cache which only represents a snapshot in moment

Specified by:
entrySet in interface Map<K,V>

getOrCreate

V getOrCreate(K key,
              Factory<V> factory)
Gets a cached value or creates a new one using the given Factory and puts the new value into the cache.

Parameters:
key -
factory -
Returns:


Copyright © 2013. All Rights Reserved.