ETS-backed in-memory cache with per-entry TTL and LRU eviction.
Used transparently by the HTTP client for cacheable GET requests.
Cache is keyed by {token_hash, path, params} so different accounts
never share cached data.
Configuration
config :aurinko,
cache_enabled: true,
cache_ttl: 60_000, # ms; default 60 seconds
cache_max_size: 5_000, # max entries before LRU eviction
cache_cleanup_interval: 30_000 # ms between sweep runsUsage
Aurinko.Cache.get("my_key") # => nil | {:ok, value}
Aurinko.Cache.put("my_key", value)
Aurinko.Cache.put("my_key", value, ttl: 5_000)
Aurinko.Cache.delete("my_key")
Aurinko.Cache.invalidate_token(token) # purge all entries for an account
Aurinko.Cache.stats()
Summary
Functions
Build a deterministic cache key from token + path + params.
Returns a specification to start this module under a supervisor.
Delete a single cache entry.
Clear the entire cache.
Retrieve a value from the cache.
Invalidate all cache entries associated with a specific token.
Store a value in the cache.
Return cache hit/miss/eviction statistics.
Types
@type cache_key() :: String.t()
@type stats() :: %{ hits: non_neg_integer(), misses: non_neg_integer(), evictions: non_neg_integer(), size: non_neg_integer() }
@type ttl_ms() :: pos_integer()
Functions
Build a deterministic cache key from token + path + params.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec delete(cache_key()) :: :ok
Delete a single cache entry.
@spec flush() :: :ok
Clear the entire cache.
Retrieve a value from the cache.
Returns {:ok, value} on a hit, nil on a miss or expired entry.
@spec invalidate_token(String.t()) :: :ok
Invalidate all cache entries associated with a specific token.
Call this after a token is refreshed or revoked.
Store a value in the cache.
Options
:ttl— Time-to-live in milliseconds. Defaults to configuredcache_ttl.
@spec stats() :: stats()
Return cache hit/miss/eviction statistics.