1 23 24 package com.sun.appserv.web.taglibs.cache; 25 26 import javax.servlet.ServletContext ; 27 import javax.servlet.ServletContextEvent ; 28 import javax.servlet.ServletContextListener ; 29 30 import com.sun.appserv.util.cache.Cache; 31 import com.sun.appserv.web.cache.CacheManager; 32 33 38 public class CacheContextListener implements ServletContextListener 39 { 40 43 public CacheContextListener() {} 44 45 48 public void contextInitialized(ServletContextEvent sce) { 49 ServletContext context = sce.getServletContext(); 50 51 CacheManager cm = (CacheManager)context.getAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME); 53 54 if (cm == null) 57 cm = new CacheManager(); 58 59 Cache cache = null; 60 try { 61 cache = cm.createCache(); 62 } catch (Exception ex) {} 63 64 if (cache != null) 66 context.setAttribute(Constants.JSPTAG_CACHE_KEY, cache); 67 } 68 69 72 public void contextDestroyed(ServletContextEvent sce) { 73 ServletContext context = sce.getServletContext(); 74 75 Cache cache = (Cache)context.getAttribute(Constants.JSPTAG_CACHE_KEY); 77 78 if (cache != null) { 79 context.removeAttribute(Constants.JSPTAG_CACHE_KEY); 80 cache.clear(); 81 } 82 } 83 } 84 | Popular Tags |