com.nutiteq.cache
Class MemoryCache

java.lang.Object
  extended by com.nutiteq.cache.MemoryCache
All Implemented Interfaces:
Cache

public class MemoryCache
extends java.lang.Object
implements Cache

Memory cache implementing LRU (least recently used) strategy. If cache is full, least recently used items will be pushed out.

Current implementation uses only actual data size. Objects/keys overhead is not calculated in cache size.


Field Summary
 
Fields inherited from interface com.nutiteq.cache.Cache
CACHE_LEVEL_MEMORY, CACHE_LEVEL_NONE, CACHE_LEVEL_PERSISTENT
 
Constructor Summary
MemoryCache(int cacheSize)
          Create a new MemoryCache instance.
 
Method Summary
 void cache(java.lang.String cacheId, byte[] data, int cacheLevel)
          Cache given data
 boolean contains(java.lang.String cacheKey)
          Does this cache contain data for given cache key
 boolean contains(java.lang.String cacheKey, int cacheLevel)
          Does the specified cache level contain given cache key
 void deinitialize()
          Clean up cache resources and, if needed, write cache definition/index somewhere.
 byte[] get(java.lang.String cacheId)
          Get cached data.
 void initialize()
          Initialize needed resources for cache.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryCache

public MemoryCache(int cacheSize)
Create a new MemoryCache instance.

Parameters:
cacheSize - cache size in bytes.
Method Detail

initialize

public void initialize()
Description copied from interface: Cache
Initialize needed resources for cache. For example read cache index.

Specified by:
initialize in interface Cache

deinitialize

public void deinitialize()
Description copied from interface: Cache
Clean up cache resources and, if needed, write cache definition/index somewhere.

Specified by:
deinitialize in interface Cache

get

public byte[] get(java.lang.String cacheId)
Description copied from interface: Cache
Get cached data.

Specified by:
get in interface Cache
Parameters:
cacheId - key that was used for data caching
Returns:
cached data

cache

public void cache(java.lang.String cacheId,
                  byte[] data,
                  int cacheLevel)
Description copied from interface: Cache
Cache given data

Specified by:
cache in interface Cache
Parameters:
cacheId - key for the cached data
data - data to be cached
cacheLevel - at which level this data needs to be cached (memory, rms, etc).

contains

public boolean contains(java.lang.String cacheKey)
Description copied from interface: Cache
Does this cache contain data for given cache key

Specified by:
contains in interface Cache
Parameters:
cacheKey - cache key checked
Returns:
if data for key present

contains

public boolean contains(java.lang.String cacheKey,
                        int cacheLevel)
Description copied from interface: Cache
Does the specified cache level contain given cache key

Specified by:
contains in interface Cache
Parameters:
cacheKey - cache key to be checked
cacheLevel - which cache levels to check
Returns:
if data for key present