📄 oscachecontroller.java
字号:
package net.java.workeffort.infrastructure.cache;import com.opensymphony.oscache.base.CacheEntry;import com.opensymphony.oscache.base.NeedsRefreshException;import com.opensymphony.oscache.general.GeneralCacheAdministrator;/** * Implementation of ICacheController for oscache. * <p> * cacheAdministrator has to be set before an object of this class can be used. * Note that this cache is seperate from the cache used by oscache for caching * html. * @author Antony Joseph */public class OsCacheController implements ICacheController { private GeneralCacheAdministrator cacheAdministrator; /** * Get the object from the cache. A RefreshRequiredException will be thrown * when no cache entry is found for the key.When the * RefreshRequiredException is thrown the calling thread should either call * putObject() or cancelObject() so that oscache can release the lock on the * cache entry. This mimicks oscache behavior. * <p> * oscache's getFromCache() will throw an NeedsRefreshException when no * entry is found in the cache. When the exception is thrown, oscache will * block other threads from using the key (cache entry) till the current * thread sets the cache value using putInCache() or till the current thread * calls cancelUpdate() which lets oscache know that the current thread does * not intent to set the cache value. See * GeneralCacheAdministrator.getFromCache() of oscache. * @param key The cache key * @throws RefreshRequiredException. */ public Object getObject(String key) throws RefreshRequiredException { try { // Get from the cache return cacheAdministrator.getFromCache(key, CacheEntry.INDEFINITE_EXPIRY); } catch (NeedsRefreshException nre) { throw new RefreshRequiredException(nre); } } public void putObject(String key, Object object) { putObject(key, object, new String[] { "net.java.workeffort.oscache.common" }); } public void putObject(String key, Object object, String[] groups) { cacheAdministrator.putInCache(key, object, groups); } public Object removeObject(String key) { cacheAdministrator.flushEntry(key); return null; } public void flushGroup(String group) { cacheAdministrator.flushGroup(group); } public void cancelUpdate(String key) { cacheAdministrator.cancelUpdate(key); } public void destroy() { cacheAdministrator.destroy(); } public GeneralCacheAdministrator getCacheAdministrator() { return cacheAdministrator; } public void setCacheAdministrator( GeneralCacheAdministrator cacheAdministrator) { this.cacheAdministrator = cacheAdministrator; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -