Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## rabbit.cache
Class NCache

    java.lang.Object
      rabbit.cache.NCache

All Implemented Interfaces:
  java.lang.Runnable

    public class NCache

extends java.lang.Object
implements java.lang.Runnable

The NCache is like a Map in lookup/insert/delete The NCache is persistent over sessions (saves itself to disk). The NCache is selfcleaning, that is it removes old stuff.

Constructor Summary
`NCache()` Create a cache that uses default values.
`NCache(java.lang.String dir)` Create a cache for the given directory.
`NCache(java.lang.String dir, long maxSize)` Create a cache for the given directory with given parameters.
`NCache(java.lang.String dir, long maxSize, long cacheTime)` Create a cachehandler.

Method Summary
`void` | `addEntry(NCacheEntry ent)` Insert a CacheEntry into the cache.
`void` | `clear()` Clear the Cache from files.
`void` | `entryChanged(NCacheEntry ent)` Signal that a cache entry have changed.
`void` | `flush()` Make sure that the cache is written to the disk.
`java.lang.String` | `getCacheDir()` Get the name of the directory where the cache stores its files.
`long` | `getCacheTime()` Get the number of miliseconds the cache stores things usually.
`int` | `getCleanLoopTime()` Get how long time the cleaner sleeps between cleanups.
`long` | `getCurrentSize()` Get the current size of the cache
`java.util.Collection<NCacheEntry>` | `getEntries()` Get the CacheEntries in the cache.
`NCacheEntry` | `getEntry(java.lang.Object o)` Get the CacheEntry assosiated with given object.
`java.lang.String` | `getEntryName(long id, boolean real)` Get the file name for a cache entry.
`java.lang.String` | `getEntryName(NCacheEntry ent)` Get the file name for a real cache entry.
`long` | `getMaxSize()` Get the maximum size for this cache.
`long` | `getNumberOfEntries()` Get the current number of entries in the cache.
`NCacheEntry` | `newEntry(java.lang.Object o)` Reserve space for a CacheEntry with key o.
`void` | `remove(java.lang.Object o)` Remove the Entry with key o from the cache.
`void` | `run()` Loop in a cleaning loop.
`void` | `setCacheDir(java.lang.String newDir)` Sets the cachedir.
`void` | `setCacheTime(long newCacheTime)` Set the standard expiry-time for CacheEntries
`void` | `setCleanLoopTime(int newCleanLoopTime)` Set how long time the cleaner sleeps between cleanups.
`void` | `setMaxSize(long newMaxSize)` Set the maximum size for this cache.
`void` | `setup(SProperties config)` Configure the cache system from the given config.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### NCache

    public NCache()

  Create a cache that uses default values.

### NCache

    public NCache(java.lang.String dir)

  Create a cache for the given directory.

  Parameters:
    `dir` - the name of the directory where the cache should store its files.

### NCache

    public NCache(java.lang.String dir,
                  long maxSize)

  Create a cache for the given directory with given parameters.

  Parameters:
    `dir` - the name of the directory where the cache should store its files.
    `maxSize` - the maximum size of the proxy.

### NCache

    public NCache(java.lang.String dir,
                  long maxSize,
                  long cacheTime)

  Create a cachehandler.

  Parameters:
    `dir` - the basedir for the cachehandler.
    `maxSize` - the maximum size of the proxy.
    `cacheTime` - how long the proxy should keep things unless specified otherwise.

Method Detail

### getCacheDir

    public java.lang.String getCacheDir()

  Get the name of the directory where the cache stores its files.

  Returns:
    the name of the cachedir

### setCacheDir

    public void setCacheDir(java.lang.String newDir)

  Sets the cachedir. This will flush the cache and make it try to read in the cache from the new dir.

  Parameters:
    `newDir` - the name of the new directory to use.

### getMaxSize

    public long getMaxSize()

  Get the maximum size for this cache.

  Returns:
    the maximum size in bytes this cache.

### setMaxSize

    public void setMaxSize(long newMaxSize)

  Set the maximum size for this cache.

  Parameters:
    `newMaxSize` - the new maximum size for the cache.

### getCacheTime

    public long getCacheTime()

  Get the number of miliseconds the cache stores things usually. This is the standard expiretime for objects, but you can set it for CacheEntries individially if you want to. NOTE 1: dont trust that an object will be in the cache this long. NOTE 2: dont trust that an object will be removed from the cache when it expires.

  Returns:
    the number of miliseconds objects are stored normally.

### setCacheTime

    public void setCacheTime(long newCacheTime)

  Set the standard expiry-time for CacheEntries

  Parameters:
    `newCacheTime` - the number of miliseconds to keep objects normally.

### getCleanLoopTime

    public int getCleanLoopTime()

  Get how long time the cleaner sleeps between cleanups.

### setCleanLoopTime

    public void setCleanLoopTime(int newCleanLoopTime)

  Set how long time the cleaner sleeps between cleanups.

  Parameters:
    `newCleanLoopTime` - the number of miliseconds to sleep.

### getCurrentSize

    public long getCurrentSize()

  Get the current size of the cache

  Returns:
    the current size of the cache in bytes.

### getNumberOfEntries

    public long getNumberOfEntries()

  Get the current number of entries in the cache.

  Returns:
    the current number of entries in the cache.

### getEntry

    public NCacheEntry getEntry(java.lang.Object o)

  Get the CacheEntry assosiated with given object.

  Parameters:
    `o` - the key.
  Returns:
    the NCacheEntry or null (if not found).

### getEntryName

    public java.lang.String getEntryName(NCacheEntry ent)

  Get the file name for a real cache entry.

### getEntryName

    public java.lang.String getEntryName(long id,
                                         boolean real)

  Get the file name for a cache entry.

  Parameters:
    `id` - the id of the cache entry
    `real` - false if this is a temporary cache file, true if it is a realized entry.

### newEntry

    public NCacheEntry newEntry(java.lang.Object o)

  Reserve space for a CacheEntry with key o.

  Parameters:
    `o` - the key for the NCacheEntry.
  Returns:
    a new CacheEntry initialized for the cache.

### addEntry

    public void addEntry(NCacheEntry ent)

  Insert a CacheEntry into the cache.

  Parameters:
    `ent` - the CacheEntry to store.

### entryChanged

    public void entryChanged(NCacheEntry ent)

  Signal that a cache entry have changed.

### remove

    public void remove(java.lang.Object o)

  Remove the Entry with key o from the cache.

  Parameters:
    `o` - the key for the CacheEntry.

### clear

    public void clear()

  Clear the Cache from files.

### getEntries

    public java.util.Collection<NCacheEntry> getEntries()

  Get the CacheEntries in the cache. Note! some entries may be invalid if you have a corruct cache.

  Returns:
    an Enumeration of the CacheEntries.

### flush

    public void flush()

  Make sure that the cache is written to the disk.

### run

    public void run()

  Loop in a cleaning loop.

  Specified by:
    `run` in interface `java.lang.Runnable`

### setup

    public void setup(SProperties config)
               throws IllegalConfigurationException

  Configure the cache system from the given config.

  Parameters:
    `config` - the properties describing the cache settings.
  Throws:
    `IllegalConfigurationException` - if some setting is strange.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD