public abstract class AbstractFileSystemCache<V> extends Object implements ApplicationCache<Key,V>, Serializable
Extends the ApplicationCache contract providing base for using file system as
storage for the cache.
ApplicationCache,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected ConcurrentMap<Key,V> |
cache |
protected Long |
ttl |
protected TimeUnit |
ttlUnit |
| Constructor and Description |
|---|
AbstractFileSystemCache()
This constructor should not be used for invoking a cache.
|
AbstractFileSystemCache(CacheType type)
Constructs an
AbstractFileSystemCache with the given type of auth token. |
AbstractFileSystemCache(CacheType type,
String cacheDir,
String cacheFile)
Constructs an
AbstractFileSystemCache with the given type of auth token, the
cache storage directory and cache file name. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
void |
destroy() |
void |
flush() |
protected Key |
generate(Object identifier)
A native strategy to generate the cache key.
|
Long |
getTtl()
Returns the set time-to-live for the entries in cache.
|
TimeUnit |
getTtlUnit()
Returns the set time-to-live time unit for the entries in cache.
|
void |
initialize()
Initializes the application cache (doesn't create it).
|
boolean |
isPresentInCache(Object key)
Checks the application cache on which the method is called for the specified key and returns
true if the condition is true, else false.
|
void |
setCacheDir(String cacheDir)
Sets the cache directory location to use with the particular type of cache in focus.
|
void |
setCacheFile(String cacheFile)
Sets the cache filename to use with the particular type of cache in focus.
|
void |
setTtl(Long ttl,
TimeUnit ttlUnit)
Sets the time-to-live & the time unit for cache entry time-to-live strategy (applicable
to each entry in the cache).
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitevictFromCache, getFromCache, putInCacheprotected Long ttl
protected TimeUnit ttlUnit
protected final ConcurrentMap<Key,V> cache
public AbstractFileSystemCache()
CacheType argument at-least.public AbstractFileSystemCache(CacheType type)
Constructs an AbstractFileSystemCache with the given type of auth token.
Sensible defaults will be used for other required parameters unless explicitly set. An
application can typically have several instances of auth cache to store different types of
auth tokens (for example, a scenario with multiple authentication/authorization providers
using different user details services).
type - the cache type to usepublic AbstractFileSystemCache(CacheType type, String cacheDir, String cacheFile)
Constructs an AbstractFileSystemCache with the given type of auth token, the
cache storage directory and cache file name. Provides better control on caching strategy out
of the box. An application can typically have several instances of auth cache to store
different types of auth tokens (for example, a scenario with multiple
authentication/authorization providers using different user details services).
type - the cache type to usecacheDir - the cache directory to usecacheFile - the cache filename to usepublic void initialize()
ApplicationCacheInitializes the application cache (doesn't create it). Can make use of a data-store for pre-fetching already stored application data (if required) typically upon container restart.
Each type of application cache is initialized separately in order to maintain sanity and usage simplicity. Thus, please be advised that a cache type must be instantiated & initialized manually before use (manually just means that extra code is required for the same).
initialize in interface ApplicationCache<Key,V>protected Key generate(Object identifier)
A native strategy to generate the cache key. Uses the key identifier and current time stamp (as creation time) and should be enough for almost everything. However, if you crave to override it, you may!
identifier - the key identifier to setKey typically an instance of CacheKey for use as key
for a cache entrypublic boolean isPresentInCache(Object key)
ApplicationCacheChecks the application cache on which the method is called for the specified key and returns true if the condition is true, else false.
Important: Note that you may use any well known java type as key like
Long or String or a custom type as long as it abides by
the contract defined by the Key interface, i.e., the key
should be uniquely identifiable using its value and not the Key instance as
whole. In short, you must override the Object.equals(Object) and
Object.hashCode() methods of that particular key type to make sure your identifier
can be uniquely distinguished from with-in the cache.
isPresentInCache in interface ApplicationCache<Key,V>key - the key to be tested for presence in the cachepublic void flush()
flush in interface ApplicationCache<Key,V>public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic void destroy()
throws Exception
destroy in interface org.springframework.beans.factory.DisposableBeanExceptionpublic void setTtl(Long ttl, TimeUnit ttlUnit)
Sets the time-to-live & the time unit for cache entry time-to-live strategy (applicable to each entry in the cache).
ttl - the ttl to setttlUnit - the ttl time unit to setpublic void setCacheDir(String cacheDir)
Sets the cache directory location to use with the particular type of cache in focus.
cacheDir - the cache directory location to usepublic void setCacheFile(String cacheFile)
Sets the cache filename to use with the particular type of cache in focus.
cacheFile - the cache filename to usepublic Long getTtl()
Returns the set time-to-live for the entries in cache.
public TimeUnit getTtlUnit()
Returns the set time-to-live time unit for the entries in cache.
Copyright © 2016. All rights reserved.