1 5 package com.opensymphony.oscache.web; 6 7 import com.opensymphony.oscache.base.Cache; 8 import com.opensymphony.oscache.base.CacheEntry; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 import java.io.Serializable ; 14 15 import javax.servlet.http.HttpSessionBindingEvent ; 16 import javax.servlet.http.HttpSessionBindingListener ; 17 18 27 public final class ServletCache extends Cache implements HttpSessionBindingListener , Serializable { 28 private static transient final Log log = LogFactory.getLog(ServletCache.class); 29 30 33 private ServletCacheAdministrator admin; 34 35 38 private int scope; 39 40 46 public ServletCache(ServletCacheAdministrator admin, int scope) { 47 super(admin.isMemoryCaching(), admin.isUnlimitedDiskCache(), admin.isOverflowPersistence()); 48 setScope(scope); 49 this.admin = admin; 50 } 51 52 60 public ServletCache(ServletCacheAdministrator admin, String algorithmClass, int limit, int scope) { 61 super(admin.isMemoryCaching(), admin.isUnlimitedDiskCache(), admin.isOverflowPersistence(), admin.isBlocking(), algorithmClass, limit); 62 setScope(scope); 63 this.admin = admin; 64 } 65 66 71 public int getScope() { 72 return scope; 73 } 74 75 private void setScope(int scope) { 76 this.scope = scope; 77 } 78 79 84 public void valueBound(HttpSessionBindingEvent event) { 85 } 86 87 93 public void valueUnbound(HttpSessionBindingEvent event) { 94 if (log.isInfoEnabled()) { 95 log.info("[Cache] Unbound from session " + event.getSession() + " using name " + event.getName()); 97 } 98 99 admin.finalizeListeners(this); 100 clear(); 101 } 102 103 115 protected boolean isStale(CacheEntry cacheEntry, int refreshPeriod, String cronExpiry) { 116 return super.isStale(cacheEntry, refreshPeriod, cronExpiry) || admin.isScopeFlushed(cacheEntry, scope); 117 } 118 } 119 | Popular Tags |