KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > descriptors > invalidation > CacheInvalidationPolicy


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.descriptors.invalidation;
23
24 import oracle.toplink.essentials.internal.identitymaps.CacheKey;
25
26 /**
27  * PUBLIC:
28  * A CacheInvalidationPolicy is used to set objects in TopLink's identity maps to be invalid
29  * following given rules. CacheInvalidationPolicy is the abstract superclass for all
30  * policies used for cache invalidation.
31  * By default in TopLink, objects do not expire in the cache. Several different policies
32  * are available to allow objects to expire. These can be set on the Descriptor.
33  * @see oracle.toplink.essentials.publicinterface.Descriptor
34  * @see oracle.toplink.essentials.descriptors.cacheinvalidation.NoExpiryCacheInvalidationPolicy
35  * @see oracle.toplink.essentials.descriptors.cacheinvalidation.DailyCacheInvalidationPolicy
36  * @see oracle.toplink.essentials.descriptors.cacheinvalidation.TimeToLiveCacheInvalidationPolicy
37  */

38 public abstract class CacheInvalidationPolicy implements java.io.Serializable JavaDoc {
39     public static final long NO_EXPIRY = -1;
40
41     /** this will represent objects that do not expire */
42     protected boolean shouldUpdateReadTimeOnUpdate = false;
43
44     /**
45        * INTERNAL:
46        * Get the next time when this object will become invalid
47        */

48     public abstract long getExpiryTimeInMillis(CacheKey key);
49
50     /**
51      * INTERNAL:
52      * Return the remaining life of this object
53      */

54     public long getRemainingValidTime(CacheKey key) {
55         long expiryTime = getExpiryTimeInMillis(key);
56         long remainingTime = expiryTime - System.currentTimeMillis();
57         if (remainingTime > 0) {
58             return remainingTime;
59         }
60         return 0;
61     }
62
63     /**
64      * INTERNAL:
65      * return true if this object is expire, false otherwise.
66      */

67     public abstract boolean isInvalidated(CacheKey key, long currentTimeMillis);
68
69     /**
70      * PUBLIC:
71      * Set whether to update the stored time an object was read when an object is updated.
72      * When the read time is updated, it indicates to TopLink that the data in the object
73      * is up to date. This means that cache invalidation checks will occur relative to the
74      * new read time.
75      * By default, the read time will not be updated when an object is updated.
76      * Often it is possible to be confident that the object is up to date after an update
77      * because otherwise the update will fail because of the locking policies in use.
78      */

79     public void setShouldUpdateReadTimeOnUpdate(boolean shouldUpdateReadTime) {
80         shouldUpdateReadTimeOnUpdate = shouldUpdateReadTime;
81     }
82
83     /**
84      * PUBLIC:
85      * Return whether objects affected by this CacheInvalidationPolicy should have
86      * the read time on their cache keys updated when an update occurs.
87      */

88     public boolean shouldUpdateReadTimeOnUpdate() {
89         return shouldUpdateReadTimeOnUpdate;
90     }
91 }
92
Popular Tags