class

Alumna::Cache

Inherits Reference < Object

Byte cache with optional TTL. MemoryCache is the in-process store. A Redis cache can implement get, set, set_nx, delete, and incr and drop in.

Values are Bytes. Alumna.cache encodes AnyData as JSON. This port does not encode.

get/set copy the byte slice. In-place mutation of a returned slice does not change the store. Call set to persist. This matches a remote store.

ttl nil means no expiry. A positive ttl is absolute from that set. The store does not slide the deadline on get.

set_nx sets only when the key is missing or expired. True if it wrote. The get rule uses set on write-through and set_nx on miss fill.

incr is atomic. Missing or non-integer values become 1. The counter has no TTL. The find rule uses it as a collection generation.

get is Bytes (hit), nil (miss), or StoreError (store down). Nil is never a failure. MemoryCache never returns StoreError.

Instance methods

delete(key : String) : Nil | StoreError
Source
get(key : String) : Bytes | Nil | StoreError
Source
incr(key : String) : Int64 | StoreError
Source
set(key : String, value : Bytes, ttl : Time::Span | Nil = nil) : Nil | StoreError
Source
set_nx(key : String, value : Bytes, ttl : Time::Span | Nil = nil) : Bool | StoreError
Source