Class ExpiringCache<T extends Cacheable>
java.lang.Object
org.deltava.util.cache.Cache<T>
org.deltava.util.cache.ExpiringCache<T>
- Type Parameters:
T
- the Cacheable object type
- Direct Known Subclasses:
ExpiringGeoCache
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
ExpiringCache.ExpiringLocalCacheEntry<U extends T>
protected class
ExpiringCache.ExpiringNullCacheEntry<U extends T>
A null cache entry for expiring caches. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adds an entry to the cache.protected void
addNullEntry
(Object key) Adds a null entry to the cache.protected void
Purges expired entries from the cache.boolean
Returns if the cache contains a particular cache key and the key has not expired.Returns an unexpired entry from the cache.Returns an entry from the cache.boolean
Queries the cache to determine if an object has expiredvoid
setExpiration
(int expiry) Sets the cache's expiration interval.
-
Field Details
-
_lastCreationTime
protected long _lastCreationTime -
_expiry
protected int _expiry
-
-
Constructor Details
-
ExpiringCache
public ExpiringCache(int maxSize, int expiryTime) Creates a new Cache.- Parameters:
maxSize
- the maximum number of entriesexpiryTime
- the expiration time in seconds- Throws:
IllegalArgumentException
- if maxSize or expiryTime are zero or negative- See Also:
-
-
Method Details
-
setExpiration
public void setExpiration(int expiry) Sets the cache's expiration interval.- Parameters:
expiry
- the expiration interval in seconds
-
get
-
contains
-
get
-
isExpired
Queries the cache to determine if an object has expired- Parameters:
key
- the cache key- Returns:
- TRUE if the object is present and expired, otherwise FALSE
-
addEntry
-
addNullEntry
Adds a null entry to the cache.- Specified by:
addNullEntry
in classCache<T extends Cacheable>
- Parameters:
key
- the entry key
-
checkOverflow
protected void checkOverflow()Purges expired entries from the cache.- Overrides:
checkOverflow
in classCache<T extends Cacheable>
-