|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.hackystat.utilities.uricache.UriCache
public class UriCache
Provides a wrapper around Apache JCS (Java Caching System) to facilitate Hackystat caching. This wrapper provides the following:
SensorBaseClient client = new SensorBaseClient(user, host); UriCache cache = new UriCache(user.getEmail(), "dailyprojectdata"); : SensorData data = (SensorData)cache.get(uriString); if (data == null) { // Cache doesn't have it, so retrieve from SensorBase and cache locally for next time. data = client.getSensorData(uriString); cache.put(uriString, data); }The cache files are in the directory ~/.hackystat/dailyprojectdata/uricache. Instances expire from the cache after one day, by default. The maximum number of in-memory instances is 10,000, by default.
Constructor Summary | |
---|---|
UriCache(java.lang.String cacheName,
java.lang.String subDir)
Creates a new UriCache instance with the specified name. |
|
UriCache(java.lang.String cacheName,
java.lang.String subDir,
java.lang.Double maxLifeDays,
java.lang.Long capacity)
Creates a new UriCache with the specified parameters. |
Method Summary | |
---|---|
void |
clear()
Removes everything in the default cache, but not any of the group caches. |
void |
clearAll()
Clears the default as well as all group caches. |
void |
clearGroup(java.lang.String group)
Removes everything in the specified group. |
static void |
dispose(java.lang.String cacheName)
Shuts down the specified cache, and removes it from the list of active caches so it can be created again. |
java.lang.Object |
get(java.io.Serializable key)
Returns the object associated with key from the cache, or null if not found. |
java.lang.Object |
getFromGroup(java.io.Serializable key,
java.lang.String group)
Implements group-based retrieval of cache elements. |
java.util.Set<java.io.Serializable> |
getGroupKeys(java.lang.String group)
Returns the set of cache keys associated with this group. |
int |
getGroupSize(java.lang.String group)
Returns the current number of elements in this cache group. |
java.util.Set<java.io.Serializable> |
getKeys()
Returns the set of keys associated with this cache. |
void |
put(java.io.Serializable key,
java.io.Serializable value)
Adds the key-value pair to this cache. |
void |
put(java.io.Serializable key,
java.io.Serializable value,
double maxLifeHours)
Adds the key-value pair to this cache with an explicit expiration time. |
void |
putInGroup(java.io.Serializable key,
java.lang.String group,
java.io.Serializable value)
Implements group-based addition of cache elements. |
void |
remove(java.io.Serializable key)
Ensures that the key-value pair associated with key is no longer in this cache. |
void |
removeFromGroup(java.io.Serializable key,
java.lang.String group)
Implements group-based removal of cache elements. |
void |
setLoggingLevel(java.lang.String level)
Sets the logging level for this logger to level. |
int |
size()
Returns the current number of elements in this cache. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UriCache(java.lang.String cacheName, java.lang.String subDir)
cacheName
- The name of this cache.subDir
- the .hackystat subdirectory in which the uricache directory holding the backing
store will be created.public UriCache(java.lang.String cacheName, java.lang.String subDir, java.lang.Double maxLifeDays, java.lang.Long capacity)
cacheName
- The name of this UriCache, which will be used as the JCS "region" and also
define the subdirectory in which the index files will live.subDir
- the .hackystat subdirectory in which the uricache directory holding the backing
store will be created.maxLifeDays
- The maximum number of days after which items expire from the cache.capacity
- The maximum number of instances to hold in the cache.Method Detail |
---|
public void put(java.io.Serializable key, java.io.Serializable value)
key
- The key, typically a UriString.value
- The value, typically the object returned from the Hackystat service.public void put(java.io.Serializable key, java.io.Serializable value, double maxLifeHours)
key
- The key, typically a UriString.value
- The value, typically the object returned from the Hackystat service.maxLifeHours
- The number of hours before this item will expire from cache.public java.lang.Object get(java.io.Serializable key)
key
- The key whose associated value is to be retrieved.
public void remove(java.io.Serializable key)
key
- The key to be removed.public void clear()
public void clearAll()
public java.util.Set<java.io.Serializable> getKeys()
public int size()
public static void dispose(java.lang.String cacheName)
cacheName
- The name of the cache to dispose of.public void putInGroup(java.io.Serializable key, java.lang.String group, java.io.Serializable value)
key
- The key.group
- The group.value
- The value.public java.lang.Object getFromGroup(java.io.Serializable key, java.lang.String group)
key
- The key.group
- The group.
public void removeFromGroup(java.io.Serializable key, java.lang.String group)
key
- The key whose value is to be removed.group
- The group.public java.util.Set<java.io.Serializable> getGroupKeys(java.lang.String group)
group
- The group.
public int getGroupSize(java.lang.String group)
group
- The name of the group.
public void clearGroup(java.lang.String group)
group
- The group name.public void setLoggingLevel(java.lang.String level)
level
- A string indicating the level, such as "FINE", "INFO", "ALL", etc.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |