Package ortus.boxlang.runtime.cache
Class BoxCacheEntry
java.lang.Object
ortus.boxlang.runtime.cache.BoxCacheEntry
- All Implemented Interfaces:
Serializable,ICacheEntry
BoxCacheEntry represents a single entry in the BoxLang cache system.
This class implements the ICacheEntry interface and provides a complete cache entry
implementation with support for timeouts, hit counting, metadata, and expiration logic.
Key features:
- Thread-safe hit counting using AtomicLong
- Configurable timeout and last access timeout
- Metadata support for additional entry information
- Automatic expiration based on creation time and last access time
- Immutable entry properties (except for hits, created, and lastAccessed timestamps)
- Efficient hash code calculation excluding the cached value
The entry supports two types of timeouts:
1. Absolute timeout: Entry expires after a fixed time from creation
2. Idle timeout (lastAccessTimeout): Entry expires if not accessed within the specified time
Setting timeout to 0 makes the entry eternal (never expires by time).
Thread Safety:
This class is thread-safe for concurrent access. The hits counter, creation time,
and last accessed time are managed using atomic operations.
- Since:
- 1.0.0
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBoxCacheEntry(Key cacheName, long timeout, long lastAccessTimeout, Key key, Object value, IStruct metadata) Constructor with metadata -
Method Summary
Modifier and TypeMethodDescription-------------------------------------------------------------------------- Interface Methods -------------------------------------------------------------------------- Mostly Getterscreated()When this cache entry was createdbooleanCheck if the entry is equal to another entry Remember this doesn't account for object valuesGet the memento of the cache entryinthashCode()Build out a hashcode for this entry based on the key, timeout, lastAccessTimeout, and cacheNamelonghits()The number of hits this cache entry has hadIncrement the hitsbooleanIs this an eternal objectbooleanVerifies if the cache entry is expired.key()The key associated with this entryWhen this cache entry was last accessedlongThe last access timeout of this cache entry in secondsmetadata()An entry can store custom information to the entryrawValue()The raw value of the cache entryReset the created datesetHits(long hits) Reset the hit countlongGet the size in bytes of this cache entry.longtimeout()The timeout of this cache entry in seconds since creation.toStruct()Get the state of the entry as a structReset the last accessed datevalue()The value associated with this entry, if any.
-
Field Details
-
EMPTY
Empty Cache Entry
-
-
Constructor Details
-
BoxCacheEntry
public BoxCacheEntry(Key cacheName, long timeout, long lastAccessTimeout, Key key, Object value, IStruct metadata) Constructor with metadata- Parameters:
cacheName- The name of the cache associated with this entrytimeout- The timeout in secondslastAccessTimeout- The last access timeout in secondskey- The keyvalue- The valuemetadata- The metadata
-
-
Method Details
-
hashCode
public int hashCode()Build out a hashcode for this entry based on the key, timeout, lastAccessTimeout, and cacheName -
equals
Check if the entry is equal to another entry Remember this doesn't account for object values -
touchLastAccessed
Reset the last accessed date- Specified by:
touchLastAccessedin interfaceICacheEntry
-
resetCreated
Reset the created date- Specified by:
resetCreatedin interfaceICacheEntry
-
incrementHits
Increment the hits- Specified by:
incrementHitsin interfaceICacheEntry
-
setHits
Reset the hit count -
cacheName
-------------------------------------------------------------------------- Interface Methods -------------------------------------------------------------------------- Mostly Getters- Specified by:
cacheNamein interfaceICacheEntry- Returns:
- The cache name
-
hits
public long hits()Description copied from interface:ICacheEntryThe number of hits this cache entry has had- Specified by:
hitsin interfaceICacheEntry- Returns:
- The number of hits
-
timeout
public long timeout()Description copied from interface:ICacheEntryThe timeout of this cache entry in seconds since creation.- Specified by:
timeoutin interfaceICacheEntry- Returns:
- The timeout in seconds
-
lastAccessTimeout
public long lastAccessTimeout()Description copied from interface:ICacheEntryThe last access timeout of this cache entry in seconds- Specified by:
lastAccessTimeoutin interfaceICacheEntry- Returns:
- The last access timeout in seconds
-
created
Description copied from interface:ICacheEntryWhen this cache entry was created- Specified by:
createdin interfaceICacheEntry- Returns:
- The creation timestamp
-
lastAccessed
Description copied from interface:ICacheEntryWhen this cache entry was last accessed- Specified by:
lastAccessedin interfaceICacheEntry- Returns:
- The last access timestamp
-
isEternal
public boolean isEternal()Description copied from interface:ICacheEntryIs this an eternal object- Specified by:
isEternalin interfaceICacheEntry- Returns:
- True if the object is eternal, false otherwise
-
key
Description copied from interface:ICacheEntryThe key associated with this entry- Specified by:
keyin interfaceICacheEntry- Returns:
- The key
-
value
Description copied from interface:ICacheEntryThe value associated with this entry, if any.- Specified by:
valuein interfaceICacheEntry- Returns:
- The attempt that represents the value from the cache
-
rawValue
Description copied from interface:ICacheEntryThe raw value of the cache entry- Specified by:
rawValuein interfaceICacheEntry- Returns:
- The raw value or null
-
metadata
Description copied from interface:ICacheEntryAn entry can store custom information to the entry- Specified by:
metadatain interfaceICacheEntry- Returns:
- A struct with the metadata
-
toStruct
Description copied from interface:ICacheEntryGet the state of the entry as a struct- Specified by:
toStructin interfaceICacheEntry
-
getMemento
Get the memento of the cache entry- Returns:
- The memento
-
isExpired
public boolean isExpired()Verifies if the cache entry is expired. The rules are as follows: - If the timeout is 0, it is eternal and never expires. - If the last access timeout is set and the last accessed time plus that timeout is before now, it is expired. - If the created time plus the timeout is before now, it is expired.- Specified by:
isExpiredin interfaceICacheEntry
-
sizeInBytes
public long sizeInBytes()Get the size in bytes of this cache entry.- Specified by:
sizeInBytesin interfaceICacheEntry- Returns:
- The size in bytes
-