KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > replacementproxy > ContentCache


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.replacementproxy;
21
22 import java.io.File JavaDoc;
23
24 import javax.servlet.http.HttpSessionBindingEvent JavaDoc;
25 import javax.servlet.http.HttpSessionBindingListener JavaDoc;
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 JavaDoc {
36
37     final static Log log = LogFactory.getLog(ContentCache.class);
38
39     ContentStash contentStash;
40     User user;
41     File JavaDoc cacheDir;
42
43     public ContentCache(User user, File JavaDoc 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     /*
58      * (non-Javadoc)
59      *
60      * @see javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
61      */

62     public void valueBound(HttpSessionBindingEvent JavaDoc arg0) {
63     }
64
65     /*
66      * (non-Javadoc)
67      *
68      * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
69      */

70     public void valueUnbound(HttpSessionBindingEvent JavaDoc 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