KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > caching > DeltaTimeCacheValidity


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.caching;
17
18 /**
19  * A validation object that remains valid for a specified amount of time.
20  *
21  * @deprecated Use the Avalon Excalibur SourceValidity implementations instead
22  * @author <a HREF="mailto:M.Homeijer@devote.nl">Michael Homeijer</a>
23  * @version CVS $Id: DeltaTimeCacheValidity.java 30932 2004-07-29 17:35:38Z vgritsenko $
24  */

25 public final class DeltaTimeCacheValidity implements CacheValidity {
26
27     private long cachedDateTime; // Holds the store-time in miliseconds
28
private long timeInCache; // maximum time allowed in cache in minutes
29

30     /**
31      * Creates validity object with timeout in minutes.
32      */

33     public DeltaTimeCacheValidity(long minutes) {
34         this.cachedDateTime = System.currentTimeMillis();
35         this.timeInCache = minutes * 60000;
36     }
37
38     /**
39      * Creates validity object with timeout in minutes, seconds.
40      */

41     public DeltaTimeCacheValidity(long minutes, long seconds) {
42         this.cachedDateTime = System.currentTimeMillis();
43         this.timeInCache = minutes * 60000 + seconds * 1000;
44     }
45
46     /**
47      * Creates validity object with timeout in minutes, seconds and milliseconds.
48      */

49     public DeltaTimeCacheValidity(long minutes, long seconds, long milliseconds) {
50         this.cachedDateTime = System.currentTimeMillis();
51         this.timeInCache = minutes * 60000 + seconds * 1000 + milliseconds;
52     }
53
54     public boolean isValid(CacheValidity validity) {
55         if (validity instanceof DeltaTimeCacheValidity) {
56             return Math.abs((((DeltaTimeCacheValidity)validity).getCachedDateTime() - this.cachedDateTime)) < this.timeInCache;
57         }
58         return false;
59     }
60
61     public long getCachedDateTime() {
62         return this.cachedDateTime;
63     }
64
65     public String JavaDoc toString() {
66         return "Delta Validity[" + this.cachedDateTime + '+' + this.timeInCache + "ms]";
67     }
68 }
69
Popular Tags