org.hypergraphdb.cache
Class SimpleCache<Key,Value>

java.lang.Object
  extended by org.hypergraphdb.cache.SimpleCache<Key,Value>
All Implemented Interfaces:
HGCache<Key,Value>

public class SimpleCache<Key,Value>
extends java.lang.Object
implements HGCache<Key,Value>


Constructor Summary
SimpleCache()
           
 
Method Summary
 void clear()
          Clear (i.e.
 Value get(Key key)
          Retrieve an element from the cache.
 Value getIfLoaded(Key key)
          Retrieve and return an element from the cache if it's already there or return null otherwise.
 RefResolver<Key,Value> getResolver()
          Return the RefResolver used to load data in the cache.
 boolean isLoaded(Key key)
          Return true if the element with the given key is currently in the cache and false otherwise.
 void remove(Key key)
          Force removal of an element from the cache.
 void setResolver(RefResolver<Key,Value> resolver)
          Set the RefResolver to be used to load data in the cache.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCache

public SimpleCache()
Method Detail

get

public Value get(Key key)
Description copied from interface: HGCache

Retrieve an element from the cache. If the element is already in the cache, it is simply returned. Otherwise, the RefResolver will be used to obtain it automatically from permanent storage.

Specified by:
get in interface HGCache<Key,Value>
Parameters:
key - The key of the element.
Returns:
The element's value.

getIfLoaded

public Value getIfLoaded(Key key)
Description copied from interface: HGCache

Retrieve and return an element from the cache if it's already there or return null otherwise. This method will not call the RefResolver when the element is not found in the cache.

Specified by:
getIfLoaded in interface HGCache<Key,Value>
Parameters:
key - The key of the element.
Returns:
The element's value or null is it's not found in the cache.

isLoaded

public boolean isLoaded(Key key)
Description copied from interface: HGCache

Return true if the element with the given key is currently in the cache and false otherwise.

Specified by:
isLoaded in interface HGCache<Key,Value>

remove

public void remove(Key key)
Description copied from interface: HGCache

Force removal of an element from the cache. This method is generally used when the data has been (or is being) removed from the permanent storage as well.

Specified by:
remove in interface HGCache<Key,Value>
Parameters:
key - The key of the element.

getResolver

public RefResolver<Key,Value> getResolver()
Description copied from interface: HGCache

Return the RefResolver used to load data in the cache.

Specified by:
getResolver in interface HGCache<Key,Value>

setResolver

public void setResolver(RefResolver<Key,Value> resolver)
Description copied from interface: HGCache

Set the RefResolver to be used to load data in the cache.

Specified by:
setResolver in interface HGCache<Key,Value>

clear

public void clear()
Description copied from interface: HGCache

Clear (i.e. force removal of) all elements from the cache.

Specified by:
clear in interface HGCache<Key,Value>