KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > web > cache > CacheHelper


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.appserv.web.cache;
25
26 import java.util.Map JavaDoc;
27
28 import javax.servlet.ServletContext JavaDoc;
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30
31 /** CacheHelper interface is an user-extensible interface to customize:
32  * a) the key generation b) whether to cache the response.
33  */

34 public interface CacheHelper {
35
36     // name of request attributes
37
public static final String JavaDoc ATTR_CACHE_MAPPED_SERVLET_NAME =
38                                     "com.sun.appserv.web.cachedServletName";
39     public static final String JavaDoc ATTR_CACHE_MAPPED_URL_PATTERN =
40                                     "com.sun.appserv.web.cachedURLPattern";
41
42     public static final int TIMEOUT_VALUE_NOT_SET = -2;
43
44     /** initialize the helper
45      * @param context the web application context this helper belongs to
46      * @exception Exception if a startup error occurs
47      */

48     public void init(ServletContext JavaDoc context, Map JavaDoc props) throws Exception JavaDoc;
49
50     /** getCacheKey: generate the key to be used to cache this request
51      * @param request incoming <code>HttpServletRequest</code> object
52      * @return the generated key for this requested cacheable resource.
53      */

54     public String JavaDoc getCacheKey(HttpServletRequest JavaDoc request);
55
56     /** isCacheable: is the response to given request cachebale?
57      * @param request incoming <code>HttpServletRequest</code> object
58      * @return <code>true</code> if the response could be cached. or
59      * <code>false</code> if the results of this request must not be cached.
60      */

61     public boolean isCacheable(HttpServletRequest JavaDoc request);
62
63     /** isRefreshNeeded: is the response to given request be refreshed?
64      * @param request incoming <code>HttpServletRequest</code> object
65      * @return <code>true</code> if the response needs to be refreshed.
66      * or return <code>false</code> if the results of this request
67      * don't need to be refreshed.
68      */

69     public boolean isRefreshNeeded(HttpServletRequest JavaDoc request);
70
71     /** get timeout for the cached response.
72      * @param request incoming <code>HttpServletRequest</code> object
73      * @return the timeout in seconds for the cached response; a return
74      * value of -1 means the response never expires and a value of -2 indicates
75      * helper cannot determine the timeout (container assigns default timeout)
76      */

77     public int getTimeout(HttpServletRequest JavaDoc request);
78
79     /**
80      * Stop the helper from active use
81      * @exception Exception if an error occurs
82      */

83     public void destroy() throws Exception JavaDoc;
84 }
85
Popular Tags