Cooldown
A TTL-based in-memory cache for managing cooldowns and temporary key-value storage
Overview
The cooldown module provides a simple key-value cache with optional TTL (time-to-live) expiration, powered by GetGameTimer(). It is exported as cooldown and can be used to gate actions, throttle events, or store short-lived state.
Functions
cooldown:set
Stores a value under key. If expiration is provided, the entry will expire after that many milliseconds.
key:stringvalue:anyexpiration:number— milliseconds until expiry
cooldown:get
Returns the cached value for key, or nil if it does not exist or has expired. Expired entries are automatically removed.
key:string- Returns:
any | nil
cooldown:update
Updates the value of an existing cache entry. Does nothing if the key is not already set.
key:stringvalue:any
cooldown:remove
Explicitly removes a key from the cache and clears its TTL.
key:string
cooldown:getOrSet
Returns the cached value for key if it exists. Otherwise, calls resolver(), stores the result with the given TTL, and returns it.
key:stringresolver:fun(): anyttl:number— milliseconds until expiry- Returns:
any