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

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

cache Laravel Sanctum token

Frequently asked questions about Cache For Laravel Sanctum
What is abe/cache-for-laravel-sanctum used for?
It is a lightweight Laravel package intended to cache Sanctum personal access token lookups so authenticated API requests do not hit the database for the same token on every call. It is an optimization layer for apps already using Sanctum, not a replacement for Sanctum itself. The package is archived and should be treated as unsupported for direct adoption.
Is abe/cache-for-laravel-sanctum abandoned and safe for production?
Yes, it is marked abandoned and its last release was in December 2023, with no maintainer security response or compatibility guarantees. It may be useful as a reference implementation, but using it directly as a production dependency carries high maintenance and security risk. For production, fork it into an internal namespace with tests or reimplement the caching pattern in your own token model.
How does caching Sanctum token lookups reduce database queries?
Sanctum normally resolves a personal access token through the database on each authenticated request. A cache-backed token finder stores the token lookup result so repeated requests can avoid that query when the cache hits. The benefit is largest in high-traffic, read-heavy APIs with a reliable shared cache; low-traffic apps may see little gain.
Which Laravel, Sanctum, and PHP versions does abe/cache-for-laravel-sanctum support?
The package has no current compatibility matrix, and its 2023 release makes Laravel 10-era support likely but not guaranteed. It is not safe to assume support for newer Laravel, Sanctum, or PHP versions without validation. Test it against the exact versions in your app, and add contract tests around Sanctum's token guard behavior if you fork it.
How do I install and configure abe/cache-for-laravel-sanctum?
Installation would normally be via Composer followed by publishing or adjusting package configuration for the cache store and TTL. Because the package is archived, direct Composer adoption should not be treated as supported. A safer path is to vendor or fork it, then document cache keys, TTL policy, invalidation events, and rollback behavior.
Does cached Sanctum token auth break logout, revocation, or token expiry?
It can introduce stale-token risk if cache entries are not invalidated when tokens are revoked, logged out, expire, or when users or abilities change. Caching must preserve Sanctum semantics for expiration, abilities, last-used timestamps, and revocation. Add failure-mode tests and keep a database fallback so stale or missing cache entries cannot bypass intended auth checks.
Which cache stores should I use with cached Sanctum tokens?
Use a reliable shared cache such as Redis or Memcached in multi-server deployments so all app instances see the same token cache. File or array cache stores are poor fits for production auth caching because they can be local, volatile, or inconsistent. Validate cache-key isolation and TTL behavior for your chosen driver.
Is abe/cache-for-laravel-sanctum safe for multi-tenant Laravel apps?
Multi-tenant use raises cache-key collision and tenant-leakage risks, so token cache keys must be namespaced by tenant and token identity. The package's age and lack of dependents mean there is little community evidence that it handles isolation correctly. A fork should include explicit tenant-isolation tests and a security review of cached bearer credentials.
What alternatives exist to abe/cache-for-laravel-sanctum?
The safer alternative is to implement cache-backed token lookup in your own PersonalAccessToken model or a custom token finder, using Laravel's cache and events. You can also fork the package internally, add a CI matrix, and wire invalidation into token creation, revocation, logout, expiry, and user updates. This avoids relying on an archived dependency while keeping the optimization.
How can I test and benchmark a fork before production?
Baseline authenticated request latency and database query counts first, then compare cache hit and miss behavior under load. Add tests for revocation, expiration, ability changes, user deletion, tenant isolation, and cache-store failures. Roll out behind a feature flag with a canary percentage and keep an immediate rollback to uncached Sanctum lookup.
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.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect