定制 spatie/laravel-flexible-cache-polyfill 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spatie/laravel-flexible-cache-polyfill

最新稳定版本:0.1.0

Composer 安装命令:

composer require spatie/laravel-flexible-cache-polyfill

包简介

Polyfill for Cache::flexible() in Laravel 10

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides a polyfill for the Cache::flexible() method, which was introduced in Laravel 11. It brings the stale while revalidating cache pattern to Laravel 10.

When using Cache::remember, some users may experience slow response times if the cached value has expired. The flexible method allows stale data to be served while the cached value is recalculated in the background after the response is sent, preventing slow response times for your users.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-flexible-cache-polyfill

Usage

Using the Cache::flexible() facade:

$value = Cache::flexible('users', [5, 10], function () {
    return DB::table('users')->get();
});

The first value (5) is the number of seconds the cache is considered "fresh". The second value (10) defines how long it can be served as stale data before recalculation is necessary.

  • 0-5 seconds: Returns cached value immediately
  • 5-10 seconds: Returns stale value, refreshes in background after response is sent
  • After 10 seconds: Cache expired, recalculates immediately

Support for all stores is available:

$value = Cache::store('redis-2')->flexible(...);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 74
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-02