org.springframework.extensions.surf.cache
Class BasicCache<K>

java.lang.Object
  extended by org.springframework.extensions.surf.cache.BasicCache<K>
All Implemented Interfaces:
ContentCache<K>
Direct Known Subclasses:
ModelObjectCache, PersistentCache

public class BasicCache<K>
extends Object
implements ContentCache<K>

This is an implementation of a purely in-memory cache that uses a HashMap to provide a basic form of caching. This class is thread safe for concurrent usage of the cache.

Author:
muzquiano, kevinr

Field Summary
protected  HashMap<String,CacheItem<K>> cache
           
protected  long timeout
           
 
Constructor Summary
BasicCache(long timeout)
          Instantiates a new basic cache.
BasicCache(long timeout, int size)
          Instantiates a new basic cache.
 
Method Summary
 K get(String key)
          Gets content stored in the cache
 void invalidate()
          Invalidates the cache
 Set<String> keys()
          Returns keys for the items in the cache
 void put(String key, K obj)
          Places content into the cache (with default timeout)
 void put(String key, K obj, long timeout)
          Places content into the cache
 void remove(String key)
          Removes a content object from the cache.
 Collection<CacheItem<K>> values()
          Returns the values for the items in the cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected final HashMap<String,CacheItem<K>> cache

timeout

protected final long timeout
Constructor Detail

BasicCache

public BasicCache(long timeout)
Instantiates a new basic cache.

Parameters:
timeout - the timeout

BasicCache

public BasicCache(long timeout,
                  int size)
Instantiates a new basic cache.

Parameters:
timeout - the timeout
size - Cache size
Method Detail

get

public K get(String key)
Description copied from interface: ContentCache
Gets content stored in the cache

Specified by:
get in interface ContentCache<K>
Parameters:
key - the key
Returns:
the object

remove

public void remove(String key)
Description copied from interface: ContentCache
Removes a content object from the cache.

Specified by:
remove in interface ContentCache<K>
Parameters:
key - the key

put

public void put(String key,
                K obj)
Description copied from interface: ContentCache
Places content into the cache (with default timeout)

Specified by:
put in interface ContentCache<K>
Parameters:
key - the key
obj - the obj

put

public void put(String key,
                K obj,
                long timeout)
Description copied from interface: ContentCache
Places content into the cache

Specified by:
put in interface ContentCache<K>
Parameters:
key - the key
obj - the obj
timeout - the timeout in milliseconds

invalidate

public void invalidate()
Description copied from interface: ContentCache
Invalidates the cache

Specified by:
invalidate in interface ContentCache<K>

values

public Collection<CacheItem<K>> values()
Returns the values for the items in the cache

Returns:
the collection

keys

public Set<String> keys()
Returns keys for the items in the cache

Returns:
the set


Copyright © 2009 SpringSource, Inc. All Rights Reserved.