Search in sources :

Example 1 with Cache

use of com.sun.appserv.util.cache.Cache in project Payara by payara.

the class CacheManager method createCache.

/**
 * create the designated cache object
 * @return the Cache implementation
 * @throws Exception
 */
public Cache createCache(int cacacity, String className) throws Exception {
    // use the context class loader to load class so that any
    // user-defined classes in WEB-INF can also be loaded.
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class cacheClass = cl.loadClass(className);
    Cache cacheImpl = (Cache) cacheClass.newInstance();
    cacheImpl.init(maxEntries, cacheProps);
    return cacheImpl;
}
Also used : Cache(com.sun.appserv.util.cache.Cache)

Example 2 with Cache

use of com.sun.appserv.util.cache.Cache in project Payara by payara.

the class CacheContextListener method contextInitialized.

/**
 * This is called when the context is created.
 */
public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    // see if a cache manager is already created and set in the context
    CacheManager cm = (CacheManager) context.getAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME);
    // to create a new cache
    if (cm == null)
        cm = new CacheManager();
    Cache cache = null;
    try {
        cache = cm.createCache();
    } catch (Exception ex) {
    }
    // set the cache as a context attribute
    if (cache != null)
        context.setAttribute(Constants.JSPTAG_CACHE_KEY, cache);
}
Also used : ServletContext(javax.servlet.ServletContext) CacheManager(com.sun.appserv.web.cache.CacheManager) Cache(com.sun.appserv.util.cache.Cache)

Example 3 with Cache

use of com.sun.appserv.util.cache.Cache in project Payara by payara.

the class CacheRequestListener method requestDestroyed.

/**
 * Receives notification that the request is about to go out of scope
 * of the web application, and clears the request's cache of JSP tag
 * body invocations (if present).
 *
 * @param sre the notification event
 */
public void requestDestroyed(ServletRequestEvent sre) {
    // Clear the cache
    ServletRequest req = sre.getServletRequest();
    Cache cache = (Cache) req.getAttribute(Constants.JSPTAG_CACHE_KEY);
    if (cache != null) {
        cache.clear();
    }
}
Also used : ServletRequest(javax.servlet.ServletRequest) Cache(com.sun.appserv.util.cache.Cache)

Example 4 with Cache

use of com.sun.appserv.util.cache.Cache in project Payara by payara.

the class CacheRequestListener method requestInitialized.

/**
 * Receives notification that the request is about to enter the scope
 * of the web application, and adds newly created cache for JSP tag
 * body invocations as a request attribute.
 *
 * @param sre the notification event
 */
public void requestInitialized(ServletRequestEvent sre) {
    ServletContext context = sre.getServletContext();
    // Check if a cache manager has already been created and set in the
    // context
    CacheManager cm = (CacheManager) context.getAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME);
    // to create a new cache
    if (cm == null) {
        cm = new CacheManager();
    }
    Cache cache = null;
    try {
        cache = cm.createCache();
    } catch (Exception ex) {
    }
    // Set the cache as a request attribute
    if (cache != null) {
        ServletRequest req = sre.getServletRequest();
        req.setAttribute(Constants.JSPTAG_CACHE_KEY, cache);
    }
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletContext(javax.servlet.ServletContext) CacheManager(com.sun.appserv.web.cache.CacheManager) Cache(com.sun.appserv.util.cache.Cache)

Example 5 with Cache

use of com.sun.appserv.util.cache.Cache in project Payara by payara.

the class CacheSessionListener method sessionDestroyed.

/**
 * Receives notification that a session is about to be invalidated, and
 * clears the session's cache of JSP tag body invocations (if present).
 *
 * @param hse the notification event
 */
public void sessionDestroyed(HttpSessionEvent hse) {
    // Clear the cache
    HttpSession session = hse.getSession();
    Cache cache = (Cache) session.getAttribute(Constants.JSPTAG_CACHE_KEY);
    if (cache != null) {
        cache.clear();
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) Cache(com.sun.appserv.util.cache.Cache)

Aggregations

Cache (com.sun.appserv.util.cache.Cache)8 ServletContext (javax.servlet.ServletContext)4 CacheManager (com.sun.appserv.web.cache.CacheManager)3 ServletRequest (javax.servlet.ServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2