01: /*
02: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation; either version 2 of the License, or
12: * (at your option) any later version.
13: *
14: * Resin Open Source is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17: * of NON-INFRINGEMENT. See the GNU General Public License for more
18: * details.
19: *
20: * You should have received a copy of the GNU General Public License
21: * along with Resin Open Source; if not, write to the
22: * Free SoftwareFoundation, Inc.
23: * 59 Temple Place, Suite 330
24: * Boston, MA 02111-1307 USA
25: *
26: * @author Scott Ferguson
27: */
28:
29: package com.caucho.server.cache;
30:
31: import com.caucho.server.connection.AbstractHttpResponse;
32: import com.caucho.server.connection.CauchoRequest;
33:
34: import com.caucho.server.dispatch.AbstractFilterChain;
35:
36: import javax.servlet.FilterChain;
37: import java.io.IOException;
38: import java.io.OutputStream;
39: import java.io.Writer;
40: import java.util.ArrayList;
41:
42: /**
43: * Represents the final servlet in a filter chain.
44: */
45: abstract public class AbstractCacheFilterChain extends
46: AbstractFilterChain implements FilterChain {
47: /**
48: * fillFromCache is called when the client needs the entire result, and
49: * the result is already in the cache.
50: *
51: * @param req the servlet request trying to get data from the cache
52: * @param response the servlet response which will receive data
53: * @param entry the cache entry to use
54: * @param isTop if true, the not-modified should be sent to the browser
55: */
56: abstract public boolean fillFromCache(CauchoRequest req,
57: AbstractHttpResponse response,
58: AbstractCacheEntry abstractEntry, boolean isTop)
59: throws IOException;
60:
61: /**
62: * Starts the caching after the headers have been sent.
63: *
64: * @param req the servlet request
65: * @param req the servlet response
66: * @param keys the saved header keys
67: * @param values the saved header values
68: * @param contentType the response content type
69: * @param charEncoding the response character encoding
70: *
71: * @return the output stream to store the cache value or null if
72: * uncacheable.
73: */
74: abstract public AbstractCacheEntry startCaching(CauchoRequest req,
75: AbstractHttpResponse res, ArrayList<String> keys,
76: ArrayList<String> values, String contentType,
77: String charEncoding, long contentLength);
78:
79: /**
80: * Update the headers when the caching has finished.
81: *
82: * @param okay if true, the cache if valid
83: */
84: abstract public void finishCaching(AbstractCacheEntry entry);
85:
86: /**
87: * Cleanup the cache entry on a failed cache attempt.
88: */
89: abstract public void killCaching(AbstractCacheEntry entry);
90: }
|