ro.isdc.wro.cache.support
Class AbstractSynchronizedCacheStrategyDecorator<K,V>

java.lang.Object
  extended by ro.isdc.wro.util.AbstractDecorator<CacheStrategy<K,V>>
      extended by ro.isdc.wro.cache.support.CacheStrategyDecorator<K,V>
          extended by ro.isdc.wro.cache.support.AbstractSynchronizedCacheStrategyDecorator<K,V>
All Implemented Interfaces:
CacheStrategy<K,V>, ObjectDecorator<CacheStrategy<K,V>>
Direct Known Subclasses:
DefaultSynchronizedCacheStrategyDecorator

public abstract class AbstractSynchronizedCacheStrategyDecorator<K,V>
extends CacheStrategyDecorator<K,V>

Ensure that the loadValue(Object) will be called only once for the same key. This behavior is important for avoiding redundant execution of expensive computation in concurrent environment which cause high memory and CPU consumption.

Since:
1.4.6
Author:
Alex Objelean

Constructor Summary
AbstractSynchronizedCacheStrategyDecorator(CacheStrategy<K,V> decorated)
           
 
Method Summary
 V get(K key)
          Restore a value from the cache.
protected abstract  V loadValue(K key)
          Loads the value associated with the key.
protected  void onBeforeGet(K key)
          Invoked just before the get method is invoked.
 void put(K key, V value)
          Put a value in the cache using a key.
 
Methods inherited from class ro.isdc.wro.cache.support.CacheStrategyDecorator
clear, destroy
 
Methods inherited from class ro.isdc.wro.util.AbstractDecorator
getDecoratedObject, getOriginalDecoratedObject, getOriginalDecoratedObject, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractSynchronizedCacheStrategyDecorator

public AbstractSynchronizedCacheStrategyDecorator(CacheStrategy<K,V> decorated)
Method Detail

get

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

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

onBeforeGet

protected void onBeforeGet(K key)
Invoked just before the get method is invoked. Can be useful for checking if resources are stale and invalidating the cache.


put

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

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

loadValue

protected abstract V loadValue(K key)
Loads the value associated with the key. This is a potential slow operation which will be prevented to be called multiple times for the same key.



Copyright © 2008-2013. All Rights Reserved.