JSecurity

org.jsecurity.cache.ehcache
Class EhCache

java.lang.Object
  extended by org.jsecurity.cache.ehcache.EhCache
All Implemented Interfaces:
Cache

public class EhCache
extends Object
implements Cache

JSecurity Cache implementation that wraps an Ehcache instance.

Since:
0.2
Author:
Jeremy Haile, Les Hazlewood

Constructor Summary
EhCache(Cache cache)
          Constructs a new EhCache instance with the given cache.
 
Method Summary
 void clear()
          Removes all elements in the cache, but leaves the cache in a useable state.
 Object get(Object key)
          Gets a value of an element which matches the given key.
 long getDiskStoreSize()
          Returns the size (in bytes) that this EhCache's disk store is consuming or -1 if that number is unknown or cannot be calculated.
 long getMemoryStoreSize()
          Returns the size (in bytes) that this EhCache's memory store is using (RAM), or -1 if that number is unknown or cannot be calculated.
 long getMemoryUsage()
          Returns the size (in bytes) that this EhCache is using in memory (RAM), or -1 if that number is unknown or cannot be calculated.
 Set keys()
          Returns a view of all the keys for entries contained in this cache.
 void put(Object key, Object value)
          Puts an object into the cache.
 void remove(Object key)
          Removes the element which matches the key.
 int size()
          Returns the number of entries in the cache.
 String toString()
          Returns "EhCache [" + cache.getName() + "]"
 Set values()
          Returns a view of all of the values contained in this cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EhCache

public EhCache(Cache cache)
Constructs a new EhCache instance with the given cache.

Parameters:
cache - - delegate EhCache instance this JSecurity cache instance will wrap.
Method Detail

get

public Object get(Object key)
           throws CacheException
Gets a value of an element which matches the given key.

Specified by:
get in interface Cache
Parameters:
key - the key of the element to return.
Returns:
The value placed into the cache with an earlier put, or null if not found or expired
Throws:
CacheException - if there is a problem accessing the underlying cache system

put

public void put(Object key,
                Object value)
         throws CacheException
Puts an object into the cache.

Specified by:
put in interface Cache
Parameters:
key - the key.
value - the value.
Throws:
CacheException - if there is a problem accessing the underlying cache system

remove

public void remove(Object key)
            throws CacheException
Removes the element which matches the key.

If no element matches, nothing is removed and no Exception is thrown.

Specified by:
remove in interface Cache
Parameters:
key - the key of the element to remove
Throws:
CacheException - if there is a problem accessing the underlying cache system

clear

public void clear()
           throws CacheException
Removes all elements in the cache, but leaves the cache in a useable state.

Specified by:
clear in interface Cache
Throws:
CacheException - if there is a problem accessing the underlying cache system

size

public int size()
Description copied from interface: Cache
Returns the number of entries in the cache.

Specified by:
size in interface Cache
Returns:
the number of entries in the cache.

keys

public Set keys()
Description copied from interface: Cache
Returns a view of all the keys for entries contained in this cache.

Specified by:
keys in interface Cache
Returns:
a view of all the keys for entries contained in this cache.

values

public Set values()
Description copied from interface: Cache
Returns a view of all of the values contained in this cache.

Specified by:
values in interface Cache
Returns:
a view of all of the values contained in this cache.

getMemoryUsage

public long getMemoryUsage()
Returns the size (in bytes) that this EhCache is using in memory (RAM), or -1 if that number is unknown or cannot be calculated.

Returns:
the size (in bytes) that this EhCache is using in memory (RAM), or -1 if that number is unknown or cannot be calculated.

getMemoryStoreSize

public long getMemoryStoreSize()
Returns the size (in bytes) that this EhCache's memory store is using (RAM), or -1 if that number is unknown or cannot be calculated.

Returns:
the size (in bytes) that this EhCache's memory store is using (RAM), or -1 if that number is unknown or cannot be calculated.

getDiskStoreSize

public long getDiskStoreSize()
Returns the size (in bytes) that this EhCache's disk store is consuming or -1 if that number is unknown or cannot be calculated.

Returns:
the size (in bytes) that this EhCache's disk store is consuming or -1 if that number is unknown or cannot be calculated.

toString

public String toString()
Returns "EhCache [" + cache.getName() + "]"

Overrides:
toString in class Object
Returns:
"EhCache [" + cache.getName() + "]"

JSecurity

Copyright © 2004-2008 JSecurity.