gdDocumentation0.8.0

API reference

GDLRUCache

Cache holding recently used values under a count and expiry limit, creating a value when missing.

Methods

setup

setup(limit: int, ttl_ms: int = 0) -> void

Configure capacity and TTL.

Parameters

NameTypeDefaultDescription
limitintRequiredMaximum number of entries retained in the cache.
ttl_msint0Entry 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) -> void

Store or replace a cache entry.

Parameters

NameTypeDefaultDescription
keyVariantRequiredKey used to select, store or authenticate the corresponding value.
valueVariantRequiredValue 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) -> Variant

Look up a key or return the fallback.

Parameters

NameTypeDefaultDescription
keyVariantRequiredKey used to select, store or authenticate the corresponding value.
fallbackVariantnullValue 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) -> Variant

Load a missing key through the factory, cache it, and return it.

Parameters

NameTypeDefaultDescription
keyVariantRequiredKey used to select, store or authenticate the corresponding value.
makeCallableRequiredCallable 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) -> bool

Check existence without refreshing access order, removing expired entries.

Parameters

NameTypeDefaultDescription
keyVariantRequiredKey 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) -> void

Remove one entry.

Parameters

NameTypeDefaultDescription
keyVariantRequiredKey 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() -> void

Clear 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() -> int

Return 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() -> int

Return 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() -> int

Return 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() -> int

Return 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() -> float

Return 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.