abe/cache-for-laravel-sanctum
A lightweight Laravel package that adds caching to Sanctum token lookups, reducing database queries on authenticated requests. Speeds up API auth for high-traffic apps while keeping Sanctum's token behavior intact. Easy to install and configure.
personal_access_tokens.token (a SHA-256 hash, unique index). That is cheap. This package only becomes a product-relevant lever when auth DB reads are a measurable share of p95 latency or DB CPU — i.e., high-RPS, token-authenticated, read-heavy API surfaces. It helps you answer "is this our bottleneck, or are we optimizing the wrong thing?"PersonalAccessToken model, or (c) take on an unmaintained Composer dependency. This artifact exists to make (b) the obvious answer.Worth pursuing (as a pattern, not a dependency) when:
personal_access_tokens reads as a top query by count, or auth is a material slice of p95/p99.file or array, and not per-node.Look elsewhere — or just don't — when:
composer.json for anything customer-facing or audited.last_used_at, ability changes, or token scopes read on every request can go stale under caching — verify before assuming compatibility.To executives (30 seconds): "A community package proposes caching Sanctum token lookups to cut a database read per authenticated request. It's a genuinely useful idea, but the package itself is abandoned — last release December 2023, archived, no users, no security support — so we should not depend on it. My recommendation: treat it as a design reference and, only if our metrics show auth is actually a bottleneck, spend roughly a day implementing the same caching internally with tests. That keeps the performance upside, avoids the supply-chain and maintenance risk, and forces us to make an explicit, documented decision about how quickly a revoked token stops working — which is a security and compliance question, not just a technical one."
To engineering: "This is a known-good pattern — cache the PersonalAccessToken lookup behind the token hash and skip the DB read on hit — not a library to install. If we proceed, it's a small override in our token model, with an explicit cache store (Redis), a namespaced key on the token hash, a TTL that is the revocation SLA, and invalidation wired into token deletion and "revoke all sessions." Must-haves before merge: tests proving revocation takes effect within the TTL, behavior verified against our Sanctum version, stampede protection on cold keys, and a feature flag so we can disable it in one config change. Please also confirm the last_used_at write path still behaves as expected under caching."
Bottom line for the roadmap: low priority, high optionality. Not a dependency; potentially a one-day, flag-gated internal optimization with a security decision attached. Revisit only when auth-path metrics justify it.
How can I help you explore Laravel packages today?