1 19 20 package com.sslexplorer.replacementproxy; 21 22 import java.io.File ; 23 24 import javax.servlet.http.HttpSessionBindingEvent ; 25 import javax.servlet.http.HttpSessionBindingListener ; 26 27 import org.apache.commons.cache.SimpleCache; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 import com.sslexplorer.properties.Property; 32 import com.sslexplorer.properties.impl.systemconfig.SystemConfigKey; 33 import com.sslexplorer.security.User; 34 35 public class ContentCache extends SimpleCache implements HttpSessionBindingListener { 36 37 final static Log log = LogFactory.getLog(ContentCache.class); 38 39 ContentStash contentStash; 40 User user; 41 File cacheDir; 42 43 public ContentCache(User user, File cacheDir, int maxMB, int maxObjects) { 44 this(user, new ContentStash(1024 * 1024 * maxMB, maxObjects, cacheDir, 20, true)); 45 this.cacheDir = cacheDir; 46 if (log.isInfoEnabled()) 47 log.info("Created new cache at " + cacheDir.getAbsolutePath() + " for " + user.getPrincipalName() + " of capacity " 48 + contentStash.capacity() + "."); 49 } 50 51 private ContentCache(User user, ContentStash stash) { 52 super(stash); 53 contentStash = (ContentStash) stash; 54 this.user = user; 55 } 56 57 62 public void valueBound(HttpSessionBindingEvent arg0) { 63 } 64 65 70 public void valueUnbound(HttpSessionBindingEvent arg0) { 71 if (Property.getPropertyBoolean(new SystemConfigKey( 72 "webForwards.cache.clearOnLogout"))) { 73 return; 74 } 75 if (log.isInfoEnabled()) 76 log.info("Clearing content cache for " + user.getPrincipalName()); 77 contentStash.clear(); 78 if (log.isInfoEnabled()) 79 log.info("Cleared content cache for " + user.getPrincipalName()); 80 } 81 82 } | Popular Tags |