com.evanmclean.evlib.cache
Class CacheManager

java.lang.Object
  extended by com.evanmclean.evlib.cache.CacheManager

public class CacheManager
extends Object

Manages a set of ConcurrentHashMapCache caches. Caches are thread-safe, expire entries after a specified time-to-live, can be bound to a maximum number of entries, and can contain strong, soft or weak references to their values.

Author:
Evan McLean McLean Computer Services (see the overview for copyright and licensing.)

Constructor Summary
CacheManager()
          Construct a cache manager with no total maximum entries.
CacheManager(int max_total_entries)
          Construct a cache manager with the specified total maximum entries.
CacheManager(int max_total_entries, org.slf4j.Logger log)
          Construct a cache manager with the specified total maximum entries.
CacheManager(org.slf4j.Logger log)
          Construct a cache manager with no total maximum entries.
 
Method Summary
 CacheBuilder builder()
           
 boolean exists(String name)
          Check if a cache with a particular name exists.
 boolean expire()
          Run an expiration over all managed caches.
<K,V> ConcurrentHashMapCache<K,V>
getCache(String name)
          Returns a previously created cache.
 Set<String> getCacheNames()
          Gets the list off all caches being managed.
 org.slf4j.Logger getLogger()
          The logger being used (or null for no logging).
 int getMaxTotalEntries()
          The total number of entries that will be held across all caches (0 for unlimited).
 void removeAllCaches()
          Remove all managed caches.
 boolean removeCache(String name)
          Remove the specified cache.
 void setLogger(org.slf4j.Logger log)
          Set the logger to use to perform detailed logging (null for no logging).
 void setMaxTotalEntries(int max_total_entries)
          Set the total number of entries that will be held across all caches (0 for unlimited).
 int size()
          Total number of entries across all managed caches.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CacheManager

public CacheManager()
Construct a cache manager with no total maximum entries.


CacheManager

public CacheManager(int max_total_entries)
Construct a cache manager with the specified total maximum entries.

Parameters:
max_total_entries - The total maximum entries to be held across all caches (0 for no overall limit).

CacheManager

public CacheManager(int max_total_entries,
                    org.slf4j.Logger log)
Construct a cache manager with the specified total maximum entries.

Parameters:
max_total_entries - The total maximum entries to be held across all caches (0 for no overall limit).
log - Use this logger to perform detailed logging (null for no logging).

CacheManager

public CacheManager(org.slf4j.Logger log)
Construct a cache manager with no total maximum entries.

Parameters:
log - Use this logger to perform detailed logging (null for no logging).
Method Detail

builder

public CacheBuilder builder()

exists

public boolean exists(String name)
Check if a cache with a particular name exists.

Parameters:
name - Name of cache to check for.
Returns:
True if a cache with that name exists.

expire

public boolean expire()
Run an expiration over all managed caches.

Returns:
Return true if there were any changes to any cache.

getCache

public <K,V> ConcurrentHashMapCache<K,V> getCache(String name)
Returns a previously created cache. Use builder() to create a new cache.

Type Parameters:
K -
V -
Parameters:
name - The name of the cache.
Returns:
The previously created cache.
Throws:
UnknownCacheException - If the cache does not exist.

getCacheNames

public Set<String> getCacheNames()
Gets the list off all caches being managed.

Returns:
Gets the list off all caches being managed.

getLogger

public org.slf4j.Logger getLogger()
The logger being used (or null for no logging).

Returns:
The logger being used (or null for no logging).

getMaxTotalEntries

public int getMaxTotalEntries()
The total number of entries that will be held across all caches (0 for unlimited).

Returns:
The total number of entries that will be held across all caches (0 for unlimited).

removeAllCaches

public void removeAllCaches()
Remove all managed caches. Removed caches pretty much become noop objects which act as empty maps that don't store anything.


removeCache

public boolean removeCache(String name)
Remove the specified cache. Removed caches pretty much become noop objects which act as empty maps that don't store anything.

Parameters:
name - Name of the cache to remove.
Returns:
True if the cache existed and was removed.

setLogger

public void setLogger(org.slf4j.Logger log)
Set the logger to use to perform detailed logging (null for no logging).

Parameters:
log - Use this logger to perform detailed logging (null for no logging).

setMaxTotalEntries

public void setMaxTotalEntries(int max_total_entries)
Set the total number of entries that will be held across all caches (0 for unlimited).

Parameters:
max_total_entries - The total number of entries that will be held across all caches (0 for unlimited).

size

public int size()
Total number of entries across all managed caches.

Returns:
Total number of entries across all managed caches.

toString

public String toString()
Overrides:
toString in class Object