ro.isdc.wro.cache.impl
Class MemoryCacheStrategy<K,V>

java.lang.Object
  extended by ro.isdc.wro.cache.impl.MemoryCacheStrategy<K,V>
All Implemented Interfaces:
CacheStrategy<K,V>
Direct Known Subclasses:
LruMemoryCacheStrategy

public class MemoryCacheStrategy<K,V>
extends Object
implements CacheStrategy<K,V>

Default CacheStrategy implementation using a Map to store values in memory.

Memory caches are thread-safe in all operations.

Author:
Alex Objelean

Field Summary
static String ALIAS
          Aliased used by provider for this implementation
 
Constructor Summary
MemoryCacheStrategy()
          Default constructor.
MemoryCacheStrategy(Map<K,V> cacheHolder)
          Constructs a new MemoryCacheStrategy and sets the Map that will be used as memory cache.
 
Method Summary
 void clear()
          Clear all cache contents.
 void destroy()
          Perform the clean up.
 V get(K key)
          Restore a value from the cache.
 void put(K key, V value)
          Put a value in the cache using a key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALIAS

public static final String ALIAS
Aliased used by provider for this implementation

See Also:
Constant Field Values
Constructor Detail

MemoryCacheStrategy

public MemoryCacheStrategy()
Default constructor. Uses a HashMap as memory cache.


MemoryCacheStrategy

public MemoryCacheStrategy(Map<K,V> cacheHolder)
Constructs a new MemoryCacheStrategy and sets the Map that will be used as memory cache.

Parameters:
cacheHolder - Map to use as memory cache. It cannot be null.
Method Detail

get

public V get(K key)
Restore a value from the cache.

Specified by:
get in interface CacheStrategy<K,V>
Parameters:
key - Object
Returns:
value Object.

put

public void put(K key,
                V value)
Put a value in the cache using a key.

Specified by:
put in interface CacheStrategy<K,V>
Parameters:
key - Object.
value - Object.

clear

public void clear()
Clear all cache contents.

Specified by:
clear in interface CacheStrategy<K,V>

destroy

public void destroy()
Perform the clean up.

Specified by:
destroy in interface CacheStrategy<K,V>


Copyright © 2008-2013. All Rights Reserved.