Package com.easydesk.cache.impl
Class JCSCacheService
java.lang.Object
com.easydesk.cache.impl.JCSCacheService
- All Implemented Interfaces:
GlobalCacheService
Spring-managed replacement for Apache easydesk's Avalon-based
JCSCacheService. Behaviorally equivalent to the original --
same GlobalCacheService contract, same underlying Apache
Commons JCS3 cache engine -- but wired and lifecycle-managed by Spring
instead of the Avalon container.
Changes from the original:
Configurable.configure(Configuration)→@Valueproperty injection (easydesk.cache.*properties).Initializable.initialize()→PostConstruct.Disposable.dispose()→PreDestroy.AbstractLogEnabled.getLogger()→ a plain SLF4J logger.- The hand-rolled daemon
Thread/Runnablehousekeeping loop →Scheduled. Spring'sTaskSchedulertakes care of the thread; this class only supplies the work to run. The consuming application must add@EnableSchedulingto one of its@Configurationclasses for this to fire. ThreadSafe(an Avalon marker interface) is dropped; the thread-safety guarantee is now simply documented here: this bean is stateless apart from the JCS cache handle itself, which is thread-safe by design, so the default Spring singleton scope is safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> voidaddObject(String objectId, CachedObject<T> cachedObject) voidRemoves every object from the cache.List<CachedObject<?>> intgetKeys()int<T> CachedObject<T> voidremoveObject(String objectId)
-
Constructor Details
-
JCSCacheService
public JCSCacheService()
-
-
Method Details
-
getObject
- Specified by:
getObjectin interfaceGlobalCacheService- Type Parameters:
T- type of object to return- Parameters:
objectId- the String id for the object- Returns:
- the cached object
- Throws:
ObjectExpiredException- if the object has expired or is not present
-
addObject
- Specified by:
addObjectin interfaceGlobalCacheService- Type Parameters:
T- type of object to add- Parameters:
objectId- the String id for the objectcachedObject- the object to add to the cache
-
removeObject
- Specified by:
removeObjectin interfaceGlobalCacheService- Parameters:
objectId- the String id for the object
-
getKeys
- Specified by:
getKeysin interfaceGlobalCacheService- Returns:
- keys of the (non-expired) objects currently in the cache
-
getCachedObjects
- Specified by:
getCachedObjectsin interfaceGlobalCacheService- Returns:
- the non-expired
CachedObjects currently in the cache
-
getCacheSize
- Specified by:
getCacheSizein interfaceGlobalCacheService- Returns:
- the current size of the cache, in bytes
- Throws:
IOException- if unable to compute the cache size
-
getNumberOfObjects
public int getNumberOfObjects()- Specified by:
getNumberOfObjectsin interfaceGlobalCacheService- Returns:
- the number of objects currently in the cache
-
flushCache
public void flushCache()Description copied from interface:GlobalCacheServiceRemoves every object from the cache.- Specified by:
flushCachein interfaceGlobalCacheService
-