Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cache For Laravel Sanctum Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Whether auth-path latency is worth engineering time now. Sanctum resolves a bearer token with a single indexed lookup on 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?"
  • Build vs. buy vs. ignore. With 17 stars, 0 dependents, an archived repo, and a last release in December 2023, this is not a vendor decision — it is a pattern decision. The realistic options are (a) do nothing, (b) copy the ~30-line approach into your own PersonalAccessToken model, or (c) take on an unmaintained Composer dependency. This artifact exists to make (b) the obvious answer.
  • Setting a token-revocation SLA. Any token cache introduces a window where a revoked or expired token still authenticates, bounded by the cache TTL. That is a product and compliance decision (logout-everywhere, compromised-credential response, SOC 2 / ISO 27001 access-termination expectations), not a purely technical one. Expect to defend a number like "revocation propagates within 60 seconds."
  • Sequencing against the token-strategy roadmap. If you are evaluating opaque tokens vs. JWT vs. session auth, this package is orthogonal and should not anchor that decision. It buys you headroom to defer a token-strategy migration, which is often its most valuable use.
  • Capacity and cost planning. A cache hit rate here translates into DB read reduction, which feeds instance sizing, read-replica need, and managed-cache spend. Useful input to a "do we need to scale the DB this quarter?" conversation.

When to Consider This Package

Worth pursuing (as a pattern, not a dependency) when:

  • Token auth is on the hot path: sustained high RPS, API-first or machine-to-machine traffic, most requests authenticated by bearer token.
  • Profiling shows personal_access_tokens reads as a top query by count, or auth is a material slice of p95/p99.
  • Tokens are long-lived and revocation latency of tens of seconds is acceptable and documented.
  • You already run Redis or Memcached as a shared cache — a real cache store, not file or array, and not per-node.
  • You have a place to own the code: a small internal override with tests beats a third-party package here.

Look elsewhere — or just don't — when:

  • Maintenance risk dominates. Archived, single-maintainer, no CVE pipeline, no compatibility guarantee against current Sanctum/Laravel. Zero dependents means zero field-testing. Do not put this in composer.json for anything customer-facing or audited.
  • Volume is modest. Below meaningful auth QPS, the indexed lookup is noise. Adopting this is pure added failure surface for no measurable gain.
  • Instant revocation is required. Session-bound tokens, short-lived JWTs, or a Redis-authoritative token store are better fits when "revoked means revoked now" is a hard requirement.
  • You need fresh token metadata. Per-request last_used_at, ability changes, or token scopes read on every request can go stale under caching — verify before assuming compatibility.
  • You're on Octane or an existing Sanctum version with caching. Check current Sanctum for built-in support first; a stale package shadowing framework internals is a debugging tax.
  • Compliance scope is tight. Introducing a cache to the authentication path expands your audit boundary and needs a documented invalidation contract. Sometimes the correct decision is to not touch auth at all.

How to Pitch It (Stakeholders)

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle