Package com.tnsai.llm.cache
Record Class CacheEntry
java.lang.Object
java.lang.Record
com.tnsai.llm.cache.CacheEntry
public record CacheEntry(String id, String promptHash, float[] embedding, String originalPrompt, Optional<String> systemPrompt, String response, Instant createdAt, Instant lastAccessedAt, long hitCount, Map<String,Object> metadata)
extends Record
Represents a cached LLM response entry.
CacheEntry stores all the necessary information to replay a cached response, including the original request parameters and the response.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CacheEntrycreate(String id, String promptHash, float[] embedding, String originalPrompt, Optional<String> systemPrompt, String response) Creates a new cache entry with current timestamp.Returns the value of thecreatedAtrecord component.float[]Returns the value of theembeddingrecord component.final booleanIndicates whether some other object is "equal to" this one.longReturns the age of this entry in seconds.final inthashCode()Returns a hash code value for this object.longhitCount()Returns the value of thehitCountrecord component.id()Returns the value of theidrecord component.booleanisExpired(long ttlSeconds) Checks if this entry has expired.Returns the value of thelastAccessedAtrecord component.metadata()Returns the value of themetadatarecord component.Returns the value of theoriginalPromptrecord component.Returns the value of thepromptHashrecord component.response()Returns the value of theresponserecord component.Returns the value of thesystemPromptrecord component.final StringtoString()Returns a string representation of this record class.Creates a copy with updated access time and hit count.Creates a copy with additional metadata.
-
Constructor Details
-
CacheEntry
public CacheEntry(String id, String promptHash, float[] embedding, String originalPrompt, Optional<String> systemPrompt, String response, Instant createdAt, Instant lastAccessedAt, long hitCount, Map<String, Object> metadata) Creates an instance of aCacheEntryrecord class.- Parameters:
id- the value for theidrecord componentpromptHash- the value for thepromptHashrecord componentembedding- the value for theembeddingrecord componentoriginalPrompt- the value for theoriginalPromptrecord componentsystemPrompt- the value for thesystemPromptrecord componentresponse- the value for theresponserecord componentcreatedAt- the value for thecreatedAtrecord componentlastAccessedAt- the value for thelastAccessedAtrecord componenthitCount- the value for thehitCountrecord componentmetadata- the value for themetadatarecord component
-
-
Method Details
-
create
public static CacheEntry create(String id, String promptHash, float[] embedding, String originalPrompt, Optional<String> systemPrompt, String response) Creates a new cache entry with current timestamp. -
withAccess
Creates a copy with updated access time and hit count. -
isExpired
public boolean isExpired(long ttlSeconds) Checks if this entry has expired.- Parameters:
ttlSeconds- Time-to-live in seconds- Returns:
- true if entry has expired
-
getAgeSeconds
public long getAgeSeconds()Returns the age of this entry in seconds. -
withSpec
Creates a copy with additional metadata.- Parameters:
key- The metadata keyvalue- The metadata value- Returns:
- New CacheEntry with updated metadata
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
promptHash
Returns the value of thepromptHashrecord component.- Returns:
- the value of the
promptHashrecord component
-
embedding
public float[] embedding()Returns the value of theembeddingrecord component.- Returns:
- the value of the
embeddingrecord component
-
originalPrompt
Returns the value of theoriginalPromptrecord component.- Returns:
- the value of the
originalPromptrecord component
-
systemPrompt
Returns the value of thesystemPromptrecord component.- Returns:
- the value of the
systemPromptrecord component
-
response
Returns the value of theresponserecord component.- Returns:
- the value of the
responserecord component
-
createdAt
Returns the value of thecreatedAtrecord component.- Returns:
- the value of the
createdAtrecord component
-
lastAccessedAt
Returns the value of thelastAccessedAtrecord component.- Returns:
- the value of the
lastAccessedAtrecord component
-
hitCount
public long hitCount()Returns the value of thehitCountrecord component.- Returns:
- the value of the
hitCountrecord component
-
metadata
Returns the value of themetadatarecord component.- Returns:
- the value of the
metadatarecord component
-