com.zwares.base.cache
Class Cache

java.lang.Object
  |
  +--com.zwares.base.cache.Cache

public class Cache
extends java.lang.Object


Nested Class Summary
 class Cache.CachedObject
           
 class Cache.ExpiringThread
           
 
Field Summary
protected  long _cacheHits
           
protected  long _cacheMisses
           
protected  Clock _clock
           
protected  int _currentSize
           
protected  long _longetivity
           
protected  int _maxSize
           
protected  DoublyLinkedList _mostRecentlyExpired
           
protected  DoublyLinkedList _mostRecentlyUsed
           
protected  java.util.Map _objectLookUp
           
protected static Clock _sharedClock
           
static int BYTES_PER_KILOBYTE
           
static int DEFAULT_CLOCK_REFRESH_INTERVAL
           
static int DEFAULT_MAX_SIZE
           
static int DEFAULT_REFRESH_INTERVAL
           
 
Constructor Summary
Cache()
           
Cache(int maxSize)
           
Cache(int maxSize, long longetivity)
           
Cache(int maxSize, long longetivity, Clock clock)
           
 
Method Summary
protected  int evict(int minSize)
           
protected  int evictExpired()
           
protected  int evictLeastRecentlyUsed()
           
protected  int evictLeastRecentlyUsed(int minSize)
           
 Cacheable get(java.lang.Object key)
           
 int getCurrentSize()
           
 long getNumberOfCacheHits()
           
 long getNumberOfCacheMisses()
           
static void main(java.lang.String[] args)
           
protected  void promote(Cache.CachedObject co)
           
 Cacheable put(java.lang.Object key, Cacheable obj)
           
 Cacheable remove(java.lang.Object key)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BYTES_PER_KILOBYTE

public static final int BYTES_PER_KILOBYTE
See Also:
Constant Field Values

DEFAULT_MAX_SIZE

public static final int DEFAULT_MAX_SIZE
See Also:
Constant Field Values

DEFAULT_REFRESH_INTERVAL

public static final int DEFAULT_REFRESH_INTERVAL
See Also:
Constant Field Values

DEFAULT_CLOCK_REFRESH_INTERVAL

public static final int DEFAULT_CLOCK_REFRESH_INTERVAL
See Also:
Constant Field Values

_objectLookUp

protected java.util.Map _objectLookUp

_mostRecentlyUsed

protected DoublyLinkedList _mostRecentlyUsed

_mostRecentlyExpired

protected DoublyLinkedList _mostRecentlyExpired

_maxSize

protected int _maxSize

_currentSize

protected int _currentSize

_cacheHits

protected long _cacheHits

_cacheMisses

protected long _cacheMisses

_clock

protected Clock _clock

_sharedClock

protected static Clock _sharedClock

_longetivity

protected long _longetivity
Constructor Detail

Cache

public Cache()

Cache

public Cache(int maxSize)

Cache

public Cache(int maxSize,
             long longetivity)

Cache

public Cache(int maxSize,
             long longetivity,
             Clock clock)
Method Detail

getCurrentSize

public int getCurrentSize()

getNumberOfCacheHits

public long getNumberOfCacheHits()

getNumberOfCacheMisses

public long getNumberOfCacheMisses()

promote

protected void promote(Cache.CachedObject co)

remove

public Cacheable remove(java.lang.Object key)

evict

protected int evict(int minSize)

evictExpired

protected int evictExpired()

evictLeastRecentlyUsed

protected int evictLeastRecentlyUsed()

evictLeastRecentlyUsed

protected int evictLeastRecentlyUsed(int minSize)

put

public Cacheable put(java.lang.Object key,
                     Cacheable obj)

get

public Cacheable get(java.lang.Object key)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)