API reference
GDLRUCache
Cache holding recently used values under a count and expiry limit, creating a value when missing.
Methods
setup(limit: int, ttl_ms: int = 0) -> voidput(key: Variant, value: Variant) -> voidtake(key: Variant, fallback: Variant = null) -> Variantfetch(key: Variant, make: Callable) -> Varianthas(key: Variant) -> boolerase(key: Variant) -> voidclear() -> voidsize() -> intlimit() -> inthit_count() -> intmiss_count() -> inthit_rate() -> float
setup
setup(limit: int, ttl_ms: int = 0) -> voidConfigure capacity and TTL.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
limit | int | Required | Maximum number of entries retained in the cache. |
ttl_ms | int | 0 | Entry lifetime in milliseconds; zero disables expiration. |
Return value
void
No value is returned.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
put
put(key: Variant, value: Variant) -> voidStore or replace a cache entry.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | Variant | Required | Key used to select, store or authenticate the corresponding value. |
value | Variant | Required | Value to store, serialize, validate or pass to the operation described above. |
Return value
void
No value is returned.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
take
take(key: Variant, fallback: Variant = null) -> VariantLook up a key or return the fallback.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | Variant | Required | Key used to select, store or authenticate the corresponding value. |
fallback | Variant | null | Value returned when the requested value is unavailable or omitted. |
Return value
Variant
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
fetch
fetch(key: Variant, make: Callable) -> VariantLoad a missing key through the factory, cache it, and return it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | Variant | Required | Key used to select, store or authenticate the corresponding value. |
make | Callable | Required | Callable used to produce a value when it is absent from the cache. |
Return value
Variant
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
has
has(key: Variant) -> boolCheck existence without refreshing access order, removing expired entries.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | Variant | Required | Key used to select, store or authenticate the corresponding value. |
Return value
bool
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
erase
erase(key: Variant) -> voidRemove one entry.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | Variant | Required | Key used to select, store or authenticate the corresponding value. |
Return value
void
No value is returned.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
clear
clear() -> voidClear entries and reset counters.
Parameters
No parameters.
Return value
void
No value is returned.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
size
size() -> intReturn the number of entries currently retained in the cache.
Parameters
No parameters.
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
limit
limit() -> intReturn the configured maximum number of retained entries.
Parameters
No parameters.
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
hit_count
hit_count() -> intReturn the accumulated count of successful cache lookups.
Parameters
No parameters.
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
miss_count
miss_count() -> intReturn the accumulated count of lookups whose key was absent.
Parameters
No parameters.
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
hit_rate
hit_rate() -> floatReturn the hit ratio from zero to one.
Parameters
No parameters.
Return value
float
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.