Package org.jboss.jca.adapters.jdbc.util
Class LRUCache<K,V>
java.lang.Object
org.jboss.jca.adapters.jdbc.util.LRUCache<K,V>
- Type Parameters:
K- The keyV- The valueK- The keyV- The value
- All Implemented Interfaces:
Cache<K,V>
Implementation of a Least Recently Used cache policy.
- Author:
- Simone Bordet
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassDouble linked cell used as entry in the cache list.classDouble queued list used to store cache entries. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()Flushes the cached objects from the cache.Returns the object paired with the specified key if it's present in the cache, otherwise must return null.voidInserts the specified object into the cache following the implemented policy.Returns the object paired with the specified key if it's present in the cache, otherwise must return null.voidRemove the cached object paired with the specified key.voidsetListener(CacheListener listener) Set the cache listenerintsize()The cache size
-
Constructor Details
-
LRUCache
public LRUCache(int max) Creates a LRU cache- Parameters:
max- The maximum number of entries
-
-
Method Details
-
get
Returns the object paired with the specified key if it's present in the cache, otherwise must return null.
Implementations of this method must have complexity of order O(1). Differently fromCache.peek(K)this method not only return whether the object is present in the cache or not, but also applies the implemented policy that will "refresh" the cached object in the cache, because this cached object was really requested. -
peek
Returns the object paired with the specified key if it's present in the cache, otherwise must return null.
Implementations of this method must have complexity of order O(1). This method should not apply the implemented caching policy to the object paired with the given key, so that a client can query if an object is cached without "refresh" its cache status. Real requests for the object must be done usingCache.get(K). -
insert
Inserts the specified object into the cache following the implemented policy.
Implementations of this method must have complexity of order O(1). -
remove
Remove the cached object paired with the specified key.
Implementations of this method must have complexity of order O(1). -
flush
public void flush()Flushes the cached objects from the cache. -
size
public int size()The cache size -
setListener
Set the cache listener- Specified by:
setListenerin interfaceCache<K,V> - Parameters:
listener- The listener
-