Cachex-backed response cache with per-resource TTLs, per-user isolation, opt-out support, and automatic invalidation on writes.
Configuration
config :tink,
cache: [
enabled: true,
max_size: 1_000
]Disabling in tests
# config/test.exs
config :tink, cache: [enabled: false]Per-call bypass
client_no_cache = %{client | cache: false}
{:ok, accounts} = Tink.Accounts.list(client_no_cache)TTLs by resource type
| TTL key | Duration | Used for |
|---|---|---|
:categories | 24 hours | Enrichment categories |
:providers | 2 hours | Provider lists and details |
:statistics | 1 hour | Statistics query results |
:default | 5 minutes | Accounts, investments, loans, etc |
:balances | 1 minute | Account balances |
:credentials | 30 seconds | Credential status |
Cache key pattern
Keys follow "user_id:resource:identifier". Invalidate a whole user's
entries with invalidate_user/1.
Summary
Functions
Delete a specific cache key.
Whether caching is enabled per application config.
Fetch a value from cache; call fallback on miss and populate cache.
Get a cached value directly. Returns {:ok, value} or {:error, :not_found}.
Build a global (non-user-scoped) cache key.
Invalidate all entries whose key starts with prefix.
Invalidate all cache entries for a user ID.
Build a scoped cache key: user_id:resource:extra.
Store a value manually.
Return raw Cachex stats for debugging.
Return the TTL in ms for a given TTL key.
Functions
@spec delete(String.t()) :: :ok
Delete a specific cache key.
@spec enabled?() :: boolean()
Whether caching is enabled per application config.
@spec fetch(String.t(), atom(), boolean(), (-> {:ok, any()} | {:error, any()})) :: {:ok, any()} | {:error, any()}
Fetch a value from cache; call fallback on miss and populate cache.
Respects cache: false on the caller-supplied client_cache flag.
Get a cached value directly. Returns {:ok, value} or {:error, :not_found}.
Build a global (non-user-scoped) cache key.
@spec invalidate_prefix(String.t()) :: :ok
Invalidate all entries whose key starts with prefix.
@spec invalidate_user(String.t()) :: :ok
Invalidate all cache entries for a user ID.
Build a scoped cache key: user_id:resource:extra.
Store a value manually.
Return raw Cachex stats for debugging.
@spec ttl(atom()) :: non_neg_integer()
Return the TTL in ms for a given TTL key.