bedrockstreaming/stale-cache-bundle
Composer 安装命令:
composer require bedrockstreaming/stale-cache-bundle
包简介
Add a stale mode into Symfony cache
README 文档
README
Introduction
This bundle aims to provide a stale cache feature to the symfony/cache component.
Basically, it does the following steps:
- extending the lifetime of cache items with a "stale period"
- during the stale period, if a cache item is fetched, try to regenerate it
- if the regeneration fails with a specifically marked error, give back the initially cached value
Usage
Configuration
First, you should configure each stale cache service:
bedrock_stale_cache: decorated_cache_pools: stale_cache_service_id: # Desired id for this new stale cache instance cache_pool: cache_pool_id # Cache pool on top of which stale cache will be used max_stale: 3600 # Stale period duration, in seconds enable_debug_logs: true # Optional (defaults to false), produce a bunch of debug logs
It will declare a @stale_cache_service_id, that you can use as an injected dependency.
The stale service will implement Symfony\Contracts\Cache\CacheInterface, so you'll need to use the get method to fetch cache items.
You can use Symfony\Contracts\Cache\TagAwareCacheInterface if you need tagging capabilities.
It's not compatible with the old Symfony\Component\Cache\Adapter\AdapterInterface.
Allow stale cache for some errors
To use stale cache, you'll have to implement Bedrock\StaleCacheBundle\Exception\UnavailableResourceException on a custom, thrown error.
The method allowStaleCacheUsage can be used for some custom logic, or you can hard code a return true.
Events
A Bedrock\StaleCacheBundle\Event\StaleCacheUsage event is sent on stale cache usage. It is strongly advised to log it, with the associated error.
Logs
Debug logs can be enabled to ensure correct stale cache usage. It should not be enabled in a production environment since it can cause performance issue.
Contribute
You can execute make quality test to execute quality checks and tests.
There is also a few make targets that can help you check this bundle is correctly supported on every Symfony versions
make composer-install-sf4make composer-install-sf5make composer-install-sf6
bedrockstreaming/stale-cache-bundle 适用场景与选型建议
bedrockstreaming/stale-cache-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.32k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 08 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bedrockstreaming/stale-cache-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bedrockstreaming/stale-cache-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2022-08-23