Class BoxCacheEntry

java.lang.Object
ortus.boxlang.runtime.cache.BoxCacheEntry
All Implemented Interfaces:
Serializable, ICacheEntry

public class BoxCacheEntry extends Object implements 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 Details

    • EMPTY

      public static final ICacheEntry 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 entry
      timeout - The timeout in seconds
      lastAccessTimeout - The last access timeout in seconds
      key - The key
      value - The value
      metadata - The metadata
  • Method Details

    • hashCode

      public int hashCode()
      Build out a hashcode for this entry based on the key, timeout, lastAccessTimeout, and cacheName
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Check if the entry is equal to another entry Remember this doesn't account for object values
      Overrides:
      equals in class Object
    • touchLastAccessed

      public ICacheEntry touchLastAccessed()
      Reset the last accessed date
      Specified by:
      touchLastAccessed in interface ICacheEntry
    • resetCreated

      public ICacheEntry resetCreated()
      Reset the created date
      Specified by:
      resetCreated in interface ICacheEntry
    • incrementHits

      public ICacheEntry incrementHits()
      Increment the hits
      Specified by:
      incrementHits in interface ICacheEntry
    • setHits

      public ICacheEntry setHits(long hits)
      Reset the hit count
    • cacheName

      public Key cacheName()
      -------------------------------------------------------------------------- Interface Methods -------------------------------------------------------------------------- Mostly Getters
      Specified by:
      cacheName in interface ICacheEntry
      Returns:
      The cache name
    • hits

      public long hits()
      Description copied from interface: ICacheEntry
      The number of hits this cache entry has had
      Specified by:
      hits in interface ICacheEntry
      Returns:
      The number of hits
    • timeout

      public long timeout()
      Description copied from interface: ICacheEntry
      The timeout of this cache entry in seconds since creation.
      Specified by:
      timeout in interface ICacheEntry
      Returns:
      The timeout in seconds
    • lastAccessTimeout

      public long lastAccessTimeout()
      Description copied from interface: ICacheEntry
      The last access timeout of this cache entry in seconds
      Specified by:
      lastAccessTimeout in interface ICacheEntry
      Returns:
      The last access timeout in seconds
    • created

      public Instant created()
      Description copied from interface: ICacheEntry
      When this cache entry was created
      Specified by:
      created in interface ICacheEntry
      Returns:
      The creation timestamp
    • lastAccessed

      public Instant lastAccessed()
      Description copied from interface: ICacheEntry
      When this cache entry was last accessed
      Specified by:
      lastAccessed in interface ICacheEntry
      Returns:
      The last access timestamp
    • isEternal

      public boolean isEternal()
      Description copied from interface: ICacheEntry
      Is this an eternal object
      Specified by:
      isEternal in interface ICacheEntry
      Returns:
      True if the object is eternal, false otherwise
    • key

      public Key key()
      Description copied from interface: ICacheEntry
      The key associated with this entry
      Specified by:
      key in interface ICacheEntry
      Returns:
      The key
    • value

      public Attempt<Object> value()
      Description copied from interface: ICacheEntry
      The value associated with this entry, if any.
      Specified by:
      value in interface ICacheEntry
      Returns:
      The attempt that represents the value from the cache
    • rawValue

      public Object rawValue()
      Description copied from interface: ICacheEntry
      The raw value of the cache entry
      Specified by:
      rawValue in interface ICacheEntry
      Returns:
      The raw value or null
    • metadata

      public IStruct metadata()
      Description copied from interface: ICacheEntry
      An entry can store custom information to the entry
      Specified by:
      metadata in interface ICacheEntry
      Returns:
      A struct with the metadata
    • toStruct

      public IStruct toStruct()
      Description copied from interface: ICacheEntry
      Get the state of the entry as a struct
      Specified by:
      toStruct in interface ICacheEntry
    • getMemento

      public IStruct 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:
      isExpired in interface ICacheEntry
    • sizeInBytes

      public long sizeInBytes()
      Get the size in bytes of this cache entry.
      Specified by:
      sizeInBytes in interface ICacheEntry
      Returns:
      The size in bytes