org.apache.commons.cache
Class SimpleCache

java.lang.Object
  extended by org.apache.commons.cache.BaseCache
      extended by org.apache.commons.cache.SimpleCache
All Implemented Interfaces:
Serializable, Cache

public class SimpleCache
extends BaseCache
implements Cache

tk.

Version:
$Id: SimpleCache.java 155435 2005-02-26 13:17:27Z dirkv $
Author:
Rodney Waldhoff
See Also:
Serialized Form

Field Summary
protected  EvictionPolicy _ep
           
protected  GroupMap _gm
           
protected  long _numCleared
           
protected  long _numRetrieveFound
           
protected  long _numRetrieveRequested
           
protected  long _numStoreRequested
           
protected  long _numStoreStored
           
protected  File _persistFile
           
protected  StashPolicy _sp
           
protected  Stash _stash
           
protected  boolean _wantsSerialized
           
 
Fields inherited from class org.apache.commons.cache.BaseCache
_retrievalListeners, _storageListeners
 
Constructor Summary
SimpleCache(Stash stash)
           
SimpleCache(Stash stash, EvictionPolicy ep)
           
SimpleCache(Stash stash, EvictionPolicy ep, StashPolicy sp)
           
SimpleCache(Stash stash, EvictionPolicy ep, StashPolicy sp, GroupMap tm)
           
SimpleCache(Stash stash, EvictionPolicy ep, StashPolicy sp, GroupMap tm, File persistFile)
           
 
Method Summary
 void clear()
          Remove all values previously stored.
 void clear(Serializable key)
          Remove any value previously stored under the given key.
 boolean contains(Serializable key)
          Returns true if I have a value associated with the given key, false otherwise.
 Serializable[] getKeysForGroup(Serializable group)
           
 long getStat(CacheStat stat)
           
static void main(String[] args)
           
static SimpleCache readFromFile(File f)
           
static SimpleCache readFromFile(String f)
           
 Serializable retrieve(Serializable key)
          Obtain the value previously stored under the given key.
 boolean store(Serializable key, Serializable val, Long expiry, Long cost, Serializable group)
          Store the specified val under the specified key and the specified group.
protected  boolean tryToEvict()
           
protected  void writeToFile()
           
 
Methods inherited from class org.apache.commons.cache.BaseCache
broadcastCleared, broadcastCleared, broadcastNotRetrieved, broadcastNotStored, broadcastRetrieved, broadcastRetrieveRequested, broadcastStored, broadcastStoreRequested, clearGroup, registerRetrievalListener, registerStorageListener, store, unregisterRetrievalListener, unregisterRetrievalListeners, unregisterStorageListener, unregisterStorageListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.cache.Cache
clearGroup, registerRetrievalListener, registerStorageListener, store, unregisterRetrievalListener, unregisterRetrievalListeners, unregisterStorageListener, unregisterStorageListeners
 

Field Detail

_gm

protected GroupMap _gm

_ep

protected EvictionPolicy _ep

_sp

protected StashPolicy _sp

_stash

protected Stash _stash

_wantsSerialized

protected boolean _wantsSerialized

_persistFile

protected File _persistFile

_numRetrieveRequested

protected long _numRetrieveRequested

_numRetrieveFound

protected long _numRetrieveFound

_numStoreRequested

protected long _numStoreRequested

_numStoreStored

protected long _numStoreStored

_numCleared

protected long _numCleared
Constructor Detail

SimpleCache

public SimpleCache(Stash stash)

SimpleCache

public SimpleCache(Stash stash,
                   EvictionPolicy ep)

SimpleCache

public SimpleCache(Stash stash,
                   EvictionPolicy ep,
                   StashPolicy sp)

SimpleCache

public SimpleCache(Stash stash,
                   EvictionPolicy ep,
                   StashPolicy sp,
                   GroupMap tm)

SimpleCache

public SimpleCache(Stash stash,
                   EvictionPolicy ep,
                   StashPolicy sp,
                   GroupMap tm,
                   File persistFile)
Method Detail

getStat

public long getStat(CacheStat stat)
             throws UnsupportedOperationException
Specified by:
getStat in interface Cache
Overrides:
getStat in class BaseCache
Throws:
UnsupportedOperationException

readFromFile

public static SimpleCache readFromFile(String f)
                                throws IOException,
                                       ClassNotFoundException
Throws:
IOException
ClassNotFoundException

readFromFile

public static SimpleCache readFromFile(File f)
                                throws IOException,
                                       ClassNotFoundException
Throws:
IOException
ClassNotFoundException

writeToFile

protected void writeToFile()

getKeysForGroup

public Serializable[] getKeysForGroup(Serializable group)
Specified by:
getKeysForGroup in interface Cache
Specified by:
getKeysForGroup in class BaseCache

store

public boolean store(Serializable key,
                     Serializable val,
                     Long expiry,
                     Long cost,
                     Serializable group)
Description copied from interface: Cache
Store the specified val under the specified key and the specified group.

Specified by:
store in interface Cache
Specified by:
store in class BaseCache
Parameters:
key - the key used to later obtain the val from me, which MUST NOT be null.
val - the val to store, which MUST NOT be null.
expiry - the timestamp at which the given val becomes stale, or null.
cost - the implemenation dependent cost of generating the val, or null.
group - a meta-key which can be used to clear the object later
Returns:
true if the val was stored, false otherwise.

retrieve

public Serializable retrieve(Serializable key)
Description copied from interface: Cache
Obtain the value previously stored under the given key.

Specified by:
retrieve in interface Cache
Specified by:
retrieve in class BaseCache
Parameters:
key - the key which MUST NOT be null.
Returns:
the previously stored value, or null.

contains

public boolean contains(Serializable key)
Description copied from interface: Cache
Returns true if I have a value associated with the given key, false otherwise.

Specified by:
contains in interface Cache
Specified by:
contains in class BaseCache
Parameters:
key - the key which MUST NOT be null.
Returns:
true if I have a value associated with the given key, false otherwise.

clear

public void clear(Serializable key)
Description copied from interface: Cache
Remove any value previously stored under the given key.

Specified by:
clear in interface Cache
Specified by:
clear in class BaseCache
Parameters:
key - the key which MUST NOT be null.

clear

public void clear()
Description copied from interface: Cache
Remove all values previously stored.

Specified by:
clear in interface Cache
Specified by:
clear in class BaseCache

tryToEvict

protected boolean tryToEvict()

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.