org.apache.turbine.services.cache
Class RefreshableCachedObject
java.lang.Object
|
+--org.apache.turbine.services.cache.CachedObject
|
+--org.apache.turbine.services.cache.RefreshableCachedObject
- All Implemented Interfaces:
- java.io.Serializable
- public class RefreshableCachedObject
- extends CachedObject
The idea of the RefreshableCachedObject is that, rather than
removing items from the cache when they become stale, we'll tell them to
refresh themselves instead. That way they'll always be in the
cache, and the code to refresh them will be run by the background
thread rather than by a user request thread. You can also set a TTL (Time
To Live) for the object. This way, if the object hasn't been touched
for the TTL period, then it will be removed from the cache.
This extends CachedObject and provides a method for refreshing the
cached object, and resetting its expire time.
- Version:
- $Id: RefreshableCachedObject.java,v 1.2 2002/01/30 16:11:21 dlr Exp $
- Author:
- Nissim Karpenstein
- See Also:
- Serialized Form
Field Summary |
private long |
lastAccess
The last time the Object was accessed from the cache. |
private long |
timeToLive
How long to wait before removing an untouched object from the cache. |
Method Summary |
long |
getTTL()
gets the timeToLive member (in milliseconds) |
boolean |
isUntouched()
Returns true if the object hasn't been touched
in the previous TTL period. |
void |
refresh()
Refresh the object and the created time. |
void |
setTTL(long l)
sets the timeToLive member (in milliseconds) |
void |
touch()
Sets the last acccess time to the current time. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
timeToLive
private long timeToLive
- How long to wait before removing an untouched object from the cache.
Negative numbers mean never remove (the default).
lastAccess
private long lastAccess
- The last time the Object was accessed from the cache.
RefreshableCachedObject
public RefreshableCachedObject(Refreshable o)
- Constructor; sets the object to expire in the default time (30
minutes).
- Parameters:
o
- The object you want to cache.
RefreshableCachedObject
public RefreshableCachedObject(Refreshable o,
long expires)
- Constructor.
- Parameters:
o
- The object to cache.expires
- How long before the object expires, in ms,
e.g. 1000 = 1 second.
setTTL
public void setTTL(long l)
- sets the timeToLive member (in milliseconds)
getTTL
public long getTTL()
- gets the timeToLive member (in milliseconds)
touch
public void touch()
- Sets the last acccess time to the current time.
isUntouched
public boolean isUntouched()
- Returns true if the object hasn't been touched
in the previous TTL period.
refresh
public void refresh()
- Refresh the object and the created time.
Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.