Weave Code
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

Laravel Flexible Cache Polyfill Laravel Package

spatie/laravel-flexible-cache-polyfill

Polyfill for Laravel 10 that adds Cache::flexible() (introduced in Laravel 11). Implements stale-while-revalidate caching so expired values can be served immediately while recalculation runs in the background, avoiding slow responses.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Feature Parity for Legacy Systems: Enables teams maintaining Laravel 10 applications to adopt the stale-while-revalidate (SWR) caching pattern (introduced in Laravel 11) without upgrading, reducing technical debt and accelerating feature delivery.
  • Performance Optimization Roadmap: Justifies prioritizing SWR for high-traffic endpoints (e.g., dashboards, API responses) where stale data is acceptable during cache regeneration, improving perceived performance.
  • Build vs. Buy: Avoids reinventing the wheel for a niche caching feature; leverages Spatie’s battle-tested polyfill to reduce dev time and risk.
  • Use Cases:
    • Legacy Laravel 10 apps needing SWR for critical paths (e.g., analytics, user profiles).
    • Feature flags where gradual rollouts require SWR to avoid race conditions.
    • Microservices with mixed Laravel versions where SWR consistency is needed.

When to Consider This Package

  • Adopt if:
    • Running Laravel 10 and need SWR caching (e.g., for API responses, dashboards).
    • SWR is a blocker for a new feature but upgrading Laravel isn’t feasible.
    • Your team lacks time/resources to implement a custom SWR solution.
  • Look elsewhere if:
    • Using Laravel 11+ (native Cache::flexible() exists).
    • SWR isn’t a priority (e.g., low-traffic apps or real-time systems where stale data is unacceptable).
    • Prefer vendor lock-in avoidance (MIT license is permissive, but dependency on Spatie is minimal).
    • Need advanced caching (e.g., multi-level caching); consider Laravel’s core or Redis packages.

How to Pitch It (Stakeholders)

For Executives: "This lightweight package lets us adopt Laravel 11’s stale-while-revalidate caching in our Laravel 10 app without a costly upgrade. It’s a 5-minute install that could cut response times for [X high-impact endpoint] by serving stale data while refreshing it in the background—like how Netflix shows you a loading spinner but keeps playing the video. No risk, just performance gains."

For Engineering: *"Spatie’s polyfill gives us Cache::flexible() for Laravel 10, enabling SWR for endpoints where stale data is tolerable (e.g., user dashboards, analytics). It’s:

  • Zero maintenance: MIT-licensed, actively maintained (last release: Dec 2025).
  • Non-intrusive: One composer install, no config changes.
  • Tested: CI includes PHP style checks and tests. Use it for [specific feature/endpoint] to reduce cache regeneration latency. Avoid if you’re already on Laravel 11 or need custom caching logic."*

For Developers: *"Need SWR in Laravel 10? This package adds Cache::flexible() with a single line:

use Spatie\FlexibleCache\FlexibleCache;
$value = Cache::flexible('key', 10, fn() => $expensiveOperation, 5);
  • How it works: Returns stale data after 10s while regenerating in 5s.
  • Where to use: Replace Cache::remember for non-critical data (e.g., cached reports).
  • Docs: GitHub."*
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport