Class: Snails::Cache
- Defined in:
- runtime/snails/cache.rbs,
runtime/snails/cache.rb
Constant Summary collapse
- MAX_ENTRIES =
Entry cap. Reaching it flushes the whole store: the bound keeps growth finite rather than hitting a byte target, and a count avoids measuring every stored value.
5000- MISSING =
Distinguishes "no entry" from a stored nil value.
Object.new
Instance Method Summary collapse
-
#clear ⇒ void
remove every entry.
-
#delete(key) ⇒ Boolean
remove one entry.
-
#exist?(key) ⇒ Boolean
whether a live entry is stored.
-
#fetch(key, expires_in: nil) ⇒ Object
return the cached value, or run the block and store its result.
-
#increment(key, amount = 1, expires_in: nil) ⇒ Integer
add to a counter.
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
-
#read(key) ⇒ Object?
the stored value, or nil on a miss or after expiry.
-
#write(key, value, expires_in: nil) ⇒ Boolean
store a value.
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
8 |
# File 'runtime/snails/cache.rbs', line 8
def initialize: () -> void
|
Instance Method Details
#clear ⇒ void
remove every entry. The harness calls this before each case so cache values and rate-limit windows do not leak across tests.
150 |
# File 'runtime/snails/cache.rb', line 150
def clear: () -> void
|
#delete(key) ⇒ Boolean
remove one entry.
93 |
# File 'runtime/snails/cache.rb', line 93
def delete: (untyped key) -> bool
|
#exist?(key) ⇒ Boolean
whether a live entry is stored.
111 |
# File 'runtime/snails/cache.rb', line 111
def exist?: (untyped key) -> bool
|
#fetch(key, expires_in: nil) ⇒ Object
return the cached value, or run the block and store its result. A miss and a stored nil are different: the hit test uses an internal sentinel, so a nil-valued entry is not recomputed.
53 |
# File 'runtime/snails/cache.rb', line 53
def fetch: (untyped key, ?expires_in: untyped) { () -> untyped } -> untyped
|
#increment(key, amount = 1, expires_in: nil) ⇒ Integer
add to a counter. The first write in a window starts it: a new entry is
stored with expires_in, and later increments keep that expiry (a
rate-limit window). A non-integer value is read through to_i.
126 |
# File 'runtime/snails/cache.rb', line 126
def increment: (untyped key, ?Integer amount, ?expires_in: untyped) -> Integer
|
#read(key) ⇒ Object?
the stored value, or nil on a miss or after expiry.
70 |
# File 'runtime/snails/cache.rb', line 70
def read: (untyped key) -> untyped
|
#write(key, value, expires_in: nil) ⇒ Boolean
store a value.
83 |
# File 'runtime/snails/cache.rb', line 83
def write: (untyped key, untyped value, ?expires_in: untyped) -> bool
|