org.riotfamily.cachius
Class Cache

java.lang.Object
  extended by org.riotfamily.cachius.Cache
All Implemented Interfaces:
Serializable

public final class Cache
extends Object
implements Serializable

The Cachius cache.

Author:
Felix Gnass
See Also:
Serialized Form

Constructor Summary
Cache(File cacheDir, int capacity, boolean enabled)
          Create the cache.
 
Method Summary
protected  void addToIndex(CacheItem item)
          Adds the item to the internal tag index.
 long getAverageOverflowInterval()
           
 int getCapacity()
           
 CacheEntry getItem(String key)
          Returns the CacheItem with the given key or creates a new one, if no entry with that key exists.
 long getMaxInvalidationTime()
           
 int getNumberOfTags()
           
 int getSize()
           
protected  void invalidateAll()
           
protected  void invalidateTaggedItems(String tag)
          Invalidates all items tagged with the given String.
protected  void removeFromIndex(CacheItem item)
          Removes the item from the internal tag index.
protected  void resetOverflowStats()
           
protected  void setCacheDir(File cacheDir)
          Sets the directory where the cache items are stored.
protected  void setCapacity(int capacity)
          Sets the cache capacity.
 void setEnabled(boolean enabled)
           
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cache

public Cache(File cacheDir,
             int capacity,
             boolean enabled)
Create the cache.

Method Detail

setCacheDir

protected final void setCacheDir(File cacheDir)
Sets the directory where the cache items are stored. If a different directory is already set, the old directory is emptied. The method is not thread-safe and therefore protected.


setCapacity

protected final void setCapacity(int capacity)
Sets the cache capacity. The method is not thread-safe and therefore protected.


setEnabled

public void setEnabled(boolean enabled)

getItem

public CacheEntry getItem(String key)
Returns the CacheItem with the given key or creates a new one, if no entry with that key exists.

Parameters:
key - The cache key
Returns:
The CacheItem for the given key

removeFromIndex

protected void removeFromIndex(CacheItem item)
Removes the item from the internal tag index.


addToIndex

protected void addToIndex(CacheItem item)
Adds the item to the internal tag index.


invalidateTaggedItems

protected void invalidateTaggedItems(String tag)
Invalidates all items tagged with the given String.


invalidateAll

protected void invalidateAll()

getCapacity

public int getCapacity()

getSize

public int getSize()

getNumberOfTags

public int getNumberOfTags()

getAverageOverflowInterval

public long getAverageOverflowInterval()

getMaxInvalidationTime

public long getMaxInvalidationTime()

resetOverflowStats

protected void resetOverflowStats()

shutdown

public void shutdown()