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: /**
20: * A validation object that remains valid for a specified amount of time.
21: *
22: * @deprecated Use the Avalon Excalibur SourceValidity implementations instead
23: * @author <a href="mailto:M.Homeijer@devote.nl">Michael Homeijer</a>
24: * @version CVS $Id: DeltaTimeCacheValidity.java 433543 2006-08-22 06:22:54Z crossley $
25: */
26: public final class DeltaTimeCacheValidity implements CacheValidity {
27:
28: private long cachedDateTime; // Holds the store-time in miliseconds
29: private long timeInCache; // maximum time allowed in cache in minutes
30:
31: /**
32: * Creates validity object with timeout in minutes.
33: */
34: public DeltaTimeCacheValidity(long minutes) {
35: this .cachedDateTime = System.currentTimeMillis();
36: this .timeInCache = minutes * 60000;
37: }
38:
39: /**
40: * Creates validity object with timeout in minutes, seconds.
41: */
42: public DeltaTimeCacheValidity(long minutes, long seconds) {
43: this .cachedDateTime = System.currentTimeMillis();
44: this .timeInCache = minutes * 60000 + seconds * 1000;
45: }
46:
47: /**
48: * Creates validity object with timeout in minutes, seconds and milliseconds.
49: */
50: public DeltaTimeCacheValidity(long minutes, long seconds,
51: long milliseconds) {
52: this .cachedDateTime = System.currentTimeMillis();
53: this .timeInCache = minutes * 60000 + seconds * 1000
54: + milliseconds;
55: }
56:
57: public boolean isValid(CacheValidity validity) {
58: if (validity instanceof DeltaTimeCacheValidity) {
59: return Math.abs((((DeltaTimeCacheValidity) validity)
60: .getCachedDateTime() - this .cachedDateTime)) < this .timeInCache;
61: }
62: return false;
63: }
64:
65: public long getCachedDateTime() {
66: return this .cachedDateTime;
67: }
68:
69: public String toString() {
70: return "Delta Validity[" + this .cachedDateTime + '+'
71: + this .timeInCache + "ms]";
72: }
73: }
|