org.norther.tammi.core.cache
Interface ResourceCache

All Superinterfaces:
Cache, CachedMap, ConcurrentMap, Map
All Known Implementing Classes:
DefaultResourceCache

public interface ResourceCache
extends Cache

Extends Cache by adding methods supporting caching of resources.

Author:
Ilkka Priha

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 long getCheckInterval()
          Gets the interval of checking validity of cached resources.
 Resource getResource(String key)
          Gets the cached resource.
 String getResourceClassName()
          Gets the name of the cached resource class to apply inside this cache.
 int getSizeLimit()
          Gets the size limit for resources to be kept in the cache.
 Resource putResource(String key, Object obj)
          Puts the specified object as a resource into the cache.
 Resource putResource(String key, Object obj, int freq)
          Puts the specified object with an expiration frequency as a resource into the cache.
 Resource removeResource(String key)
          Removes the cached resource.
 void setCheckInterval(long msecs)
          Gets the interval of checking validity of cached resources.
 void setResource(String key, Resource res)
          Sets the cached resource.
 void setResource(String key, Resource res, int freq)
          Sets the cached resource with an expiration frequency.
 void setResourceClassName(String className)
          Sets the name of the cached resource class to apply inside this cache.
 void setSizeLimit(int limit)
          Sets a size limit for resources to be kept in the cache.
 
Methods inherited from interface org.norther.tammi.acorn.cache.CachedMap
add, add, expire, expireAll, expireFraction, get, getDefaultExpirationTime, getExpirationLimit, getExpirationSleepInterval, getExpirationThreshold, getMaxExpirationTime, isAllowExpired, isAutoRefreshDeclined, isDiscardOverloaded, put, putIfAbsent, refresh, refresh, setAllowExpired, setAutoRefreshDeclined, setDefaultExpirationTime, setDiscardOverloaded, setExpirationLimit, setExpirationSleepInterval, setExpirationThreshold, setMaxExpirationTime
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, remove, replace, replace
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Method Detail

getCheckInterval

long getCheckInterval()
Gets the interval of checking validity of cached resources.

Returns:
the check interval in milliseconds.

setCheckInterval

void setCheckInterval(long msecs)
Gets the interval of checking validity of cached resources.

Parameters:
msecs - the check interval in milliseconds (-1 = only once).

getSizeLimit

int getSizeLimit()
Gets the size limit for resources to be kept in the cache.

Returns:
the limit for a resource size in bytes.

setSizeLimit

void setSizeLimit(int limit)
Sets a size limit for resources to be kept in the cache.

Parameters:
limit - a limit for a resource size in bytes (-1 = unlimited).

getResourceClassName

String getResourceClassName()
Gets the name of the cached resource class to apply inside this cache. The class must implement the CachedResource interface and have a public constructor CachedResource((String) name, (Object) source).

Returns:
the class name of the cached resource.

setResourceClassName

void setResourceClassName(String className)
Sets the name of the cached resource class to apply inside this cache. The class must implement the CachedResource interface and have a public constructor CachedResource((String) name, (Object) source).

Parameters:
className - the class name of the cached resource.

getResource

Resource getResource(String key)
Gets the cached resource.

Parameters:
key - the key of the cached resource.
Returns:
the cached resource, or null if not cached.

setResource

void setResource(String key,
                 Resource res)
Sets the cached resource.

Note that the size limit is not applied.

Parameters:
key - the key of the cached resource.
res - the cached resource.

setResource

void setResource(String key,
                 Resource res,
                 int freq)
Sets the cached resource with an expiration frequency.

Note that the size limit is not applied.

Parameters:
key - the key of the cached resource.
res - the cached resource.
freq - the expiration frequency.

putResource

Resource putResource(String key,
                     Object obj)
                     throws ConstructionException
Puts the specified object as a resource into the cache. An existing resource mapped to the specified key is replaced with the given one if they are not equal.

Parameters:
key - the key of the cached object.
obj - the object to cache.
Returns:
the cached resource.
Throws:
ConstructionException - if construction fails.

putResource

Resource putResource(String key,
                     Object obj,
                     int freq)
                     throws ConstructionException
Puts the specified object with an expiration frequency as a resource into the cache. An existing resource mapped to the specified key is replaced with the given one if they are not equal.

Parameters:
key - the key of the cached object.
obj - the object to cache.
freq - the expiration frequency.
Returns:
the cached resource.
Throws:
ConstructionException - if construction fails.

removeResource

Resource removeResource(String key)
Removes the cached resource.

Parameters:
key - the key of the cached resource.
Returns:
the removed resource.


Copyright © 2004 The Norther Organization. All rights reserved.