com.nutiteq.cache
Class RmsCache

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

public class RmsCache
extends java.lang.Object
implements Cache

Caching inside record stores. Uses a collection of record stores (buckets) for caching. Record stores are created for every bucket and cache index.

Implemented with LRU (least recently used) strategy.

Values given in constructor are for maximum bucket size and number of buckets. If phone limits are smaller, then this implementation adapts to it.
For example cache with five buckets of size 64kB is created, but phone has a max limit of three record stores for application with maximum size of 30kB. Then we will have a cache with two buckets (one will be used for index) with total size of 60kB.

Memory usage estimates

Cache holds a index of all files in memory and based on tile size and tile URL length it can differ significantly.

With OpenStreetMap tiles index size with 64kB bucket would be around 500-600 bytes. Bucket would contain 5-6 10kB images and for every image we would need to have in memory tile URL for cache key, bucket location and there is some object overhead.

With CloudMade tiles cache index size for 64kB bucket would be ~10kB. CloudMade images are a lot smaller (usually around 500B) and this also increases number of URLs needed for cache keys.


Field Summary
 
Fields inherited from interface com.nutiteq.cache.Cache
CACHE_LEVEL_MEMORY, CACHE_LEVEL_NONE, CACHE_LEVEL_PERSISTENT
 
Constructor Summary
RmsCache(java.lang.String cachePrefix, int maxBucketSize, int numberOfBuckets)
          Creates a new record stores cache with given number of cache buckets.
 
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

RmsCache

public RmsCache(java.lang.String cachePrefix,
                int maxBucketSize,
                int numberOfBuckets)
Creates a new record stores cache with given number of cache buckets.

Parameters:
cachePrefix - prefix for cache
maxBucketSize - maximum bucket size in bytes
numberOfBuckets - number of buckets to be used
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

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).

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

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