01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.caching;
18:
19: import java.io.Serializable;
20:
21: /**
22: * This is a "simple" cache key that does not consider the components used in the
23: * pipeline. It simply consists of a key (unique identifier for the request) and
24: * a boolean value that defines if the key is for a complete pipeline call or
25: * for an internal pipeline call.
26: *
27: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
28: * @version CVS $Id: IdentifierCacheKey.java 433543 2006-08-22 06:22:54Z crossley $
29: * @since 2.1.1
30: */
31: public class IdentifierCacheKey implements Serializable {
32:
33: /** The key */
34: final protected String key;
35:
36: /** Is this an external pipeline call? */
37: final protected boolean external;
38:
39: /** cache key */
40: final protected String cacheKey;
41:
42: /** cache toString() */
43: protected String toString;
44:
45: /**
46: * Constructor
47: */
48: public IdentifierCacheKey(String key, boolean external) {
49: this .key = key;
50: this .external = external;
51: final StringBuffer buf = new StringBuffer();
52: buf.append(this .external).append(':').append(this .key);
53: this .cacheKey = buf.toString();
54: }
55:
56: /**
57: * Compare
58: */
59: public boolean equals(Object object) {
60: if (object instanceof IdentifierCacheKey) {
61: IdentifierCacheKey pck = (IdentifierCacheKey) object;
62: return this .cacheKey.equals(pck.cacheKey);
63: }
64: return false;
65: }
66:
67: /**
68: * Generate a hash code
69: */
70: public int hashCode() {
71: return this .cacheKey.hashCode();
72: }
73:
74: /**
75: * toString
76: * The FilesystemStore uses toString!
77: */
78: public String toString() {
79: if (this .toString == null) {
80: StringBuffer buffer = new StringBuffer();
81: buffer.append("IK:");
82: buffer.append(this .cacheKey);
83: this .toString = buffer.toString();
84: }
85: return toString;
86: }
87:
88: /**
89: * The cache key
90: */
91: public String getKey() {
92: return this.key;
93: }
94: }
|