Package stanford.netdb.util
Class Cache<T>
- java.lang.Object
-
- stanford.netdb.util.Cache<T>
-
public class Cache<T> extends java.lang.ObjectCreate a cache, that tracks its age. Additionally, a 'shared cache' is created. Caches can be added to this shared space and retrieved at any time.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longage()Fetch the maximum age before this cache is considered old.Cache<T>age(long age)Set the maximum age before this cache is considered old.Tdata()Fetch the data that is cachedCache<T>data(T new_cache)Set the data that is cached, and updates when the cache was updated.static Cachedelete(java.lang.String name)Remove a cache from the shared cache.static Cache<java.util.Hashtable<java.lang.String,java.lang.String>>fetch_hashtable_cache(java.lang.String name)Fetch a cache, containing a Hashtablefor data, from the shared cache. static Cache<java.util.Hashtable<java.lang.String,java.lang.String>>fetch_hashtable_cache(java.lang.String name, long age)Fetch a cache, containing a Hashtablefor data, from the shared cache. voidinvalidate()Flag this cache as 'old'.java.lang.Booleanis_old()Test the cache's age.static java.lang.Booleanis_old(java.lang.String name)Test a shared cache's age.java.util.Datelast_update()Fetch the maximum age before this cache is considered old.static Cacheshared(java.lang.String name)Fetch a cache from the shared cache.static voidshared(java.lang.String name, Cache cache)Add/Update a cache to the shared cache.java.lang.Longsize()
-
-
-
Method Detail
-
last_update
public java.util.Date last_update()
Fetch the maximum age before this cache is considered old.
-
age
public long age()
Fetch the maximum age before this cache is considered old.
-
data
public T data()
Fetch the data that is cached
-
data
public Cache<T> data(T new_cache)
Set the data that is cached, and updates when the cache was updated.
-
is_old
public java.lang.Boolean is_old()
Test the cache's age. If the data hasn't yet been set, it is considered 'old'.
-
invalidate
public void invalidate()
Flag this cache as 'old'.
-
size
public java.lang.Long size()
-
shared
public static void shared(java.lang.String name, Cache cache)Add/Update a cache to the shared cache.
-
shared
public static Cache shared(java.lang.String name)
Fetch a cache from the shared cache.
-
delete
public static Cache delete(java.lang.String name)
Remove a cache from the shared cache. If the cache doesn't exist, nothing is done.- Returns:
- The cache that was removed (if one was removed).
-
is_old
public static java.lang.Boolean is_old(java.lang.String name)
Test a shared cache's age. If the cache name doesn't exist, it is considered old.- See Also:
is_old()
-
fetch_hashtable_cache
public static Cache<java.util.Hashtable<java.lang.String,java.lang.String>> fetch_hashtable_cache(java.lang.String name)
Fetch a cache, containing a Hashtablefor data, from the shared cache. If it doesn't exist, it will be created (using the default age) before returning. - Parameters:
name- The name of the shared cache to create and/or fetch- Returns:
- a Cache
>
-
fetch_hashtable_cache
public static Cache<java.util.Hashtable<java.lang.String,java.lang.String>> fetch_hashtable_cache(java.lang.String name, long age)
Fetch a cache, containing a Hashtablefor data, from the shared cache. If it doesn't exist, it will be created (using the specified age) before returning. - Parameters:
name- The name of the shared cache to create and/or fetchage- The age of the shared cache being created. If the cache already exists, the value of this parameter will have no effect.- Returns:
- a Cache
>
-
-