laravel-enso/cache-chain
Composer 安装命令:
composer require laravel-enso/cache-chain
包简介
Cache chain for Laravel Enso
README 文档
README
Description
Cache Chain is a layered Laravel cache store that lets multiple cache providers behave like a single repository.
It reads values from the first configured cache store that contains the key, then backfills the missing lower layers so subsequent reads can be served faster. Write operations are propagated to every configured provider, which makes the chain useful when combining fast local caches with slower persistent ones.
The package works independently of the Enso ecosystem and integrates through Laravel's native Cache::store() extension mechanism.
Installation
Install the package:
composer require laravel-enso/cache-chain
The service provider is auto-registered and adds a chain cache driver to Laravel.
Configure a cache store that uses the driver:
'stores' => [ 'chain' => [ 'driver' => 'chain', 'providers' => ['array', 'redis', 'file'], 'defaultTTL' => 300, ], ],
providers must contain the cache stores that will participate in the chain, ordered from the fastest or most local layer to the slowest or most persistent one.
defaultTTL controls how values discovered in deeper layers are written back into missing upper layers. When it is omitted or set to 0, backfilled values are cached forever.
Features
- Registers a custom Laravel cache driver named
chain. - Supports combining multiple cache stores into one layered repository.
- Reads from the first provider that contains the requested key.
- Backfills missing lower layers when a value is found in a superior layer.
- Propagates
put,forever,forget,flush, andtouchoperations to every configured provider. - Keeps
increment()anddecrement()values in sync across all layers. - Delegates cache locks to the last configured provider that supports Laravel locks.
Usage
Use the configured store like any other Laravel cache repository:
use Illuminate\Support\Facades\Cache; $cache = Cache::store('chain'); $cache->put('settings.theme', 'dark', 300); $theme = $cache->get('settings.theme');
Layered reads are automatic. If the first provider misses and a deeper provider contains the value, the package returns that value and repopulates the missing upper layers.
Increment and decrement operations keep all configured stores aligned:
$cache = Cache::store('chain'); $cache->put('visits', 10, 300); $cache->increment('visits', 5);
::: warning Note
providers cannot be empty.
If you want to use cache locks through the chain, at least one configured provider must support Laravel's lock API. :::
API
Driver Registration
LaravelEnso\CacheChain\AppServiceProvider
The package registers a custom cache driver through Cache::extend('chain', ...).
Store Configuration
Required configuration keys for a chain store:
driverproviders
Optional configuration keys:
defaultTTL
Core Class
LaravelEnso\CacheChain\Extensions\Chain
Key methods:
providers(array $providers)get($key)put($key, $value, $seconds)touch($key, $seconds)increment($key, $value = 1)decrement($key, $value = 1)forever($key, $value)forget($key)flush()lock($name, $seconds = 0, $owner = null)restoreLock($name, $owner)
Exceptions
LaravelEnso\CacheChain\Exceptions\Chain
Exception factories:
providers()lockProvider()
Depends On
Framework dependency:
Contributions
are welcome. Pull requests are great, but issues are good too.
Thank you to all the people who already contributed to Enso!
laravel-enso/cache-chain 适用场景与选型建议
laravel-enso/cache-chain 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.45k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「laravel-cache」 「laravel-enso」 「cache-chain」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laravel-enso/cache-chain 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravel-enso/cache-chain 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laravel-enso/cache-chain 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Model caching dependency for Laravel Enso
repository php library
Enums for Laravel Enso
Company management dependency for Laravel Enso
Person management for Laravel Enso
Image transformer dependency for Laravel Enso
统计信息
- 总下载量: 7.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-26