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 classExpiringCache.ExpiringLocalCacheEntry<U extends T>protected classExpiringCache.ExpiringNullCacheEntry<U extends T>A null cache entry for expiring caches. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds an entry to the cache.protected voidaddNullEntry(Object key) Adds a null entry to the cache.protected voidPurges expired entries from the cache.booleanReturns 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.booleanQueries the cache to determine if an object has expiredvoidsetExpiration(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:
addNullEntryin classCache<T extends Cacheable>- Parameters:
key- the entry key
-
checkOverflow
protected void checkOverflow()Purges expired entries from the cache.- Overrides:
checkOverflowin classCache<T extends Cacheable>
-