byerikas/cache-tags
Composer 安装命令:
composer require byerikas/cache-tags
包简介
Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.
README 文档
README
Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.
This is done by adding a new store driver, redis-tags, that adds a different functionality.
Laravel 10+ changed how cache logic works, removing the ability to retrieve an item if not using the exact tags that were present when setting a cache key. E.g.:
Cache::tags(["tag1", "tag2"])->put("key", true); Cache::tags(["tag1"])->get("key"); //Will result in the default value (null) Cache::tags(["tag1", "tag2"])->get("key"); //Will result in true Cache::tags(["tag2", "tag1"])->get("key"); //Will result in the default value (null)
This changes how that works. Tags no longer have an impact on keys. Tags are used strictly for tagging, and not for creating different key namespaces. E.g:
Cache::tags(["tag1", "tag2"])->put("key", true); Cache::tags(["tag1"])->get("key"); //Will result in true Cache::tags(["tag2", "tag1"])->get("key"); //Will result in true Cache::get("key"); //Will result in true
Using Cache::forever() will now store items for 100 days, not forever, to allow the values to be memory managed, instead of tags.
Flushing tags - one is enough to flush the value out of the cache. This leaves some empty references in tag sets but is mitigated by the stale tag pruning command. (see Installation)
Cache::tags(["tag1", "tag2"])->put("key", true); Cache::tags(["tag1"])->flush(); //Will flush "key" Cache::flush(); //Will flush "key"
Limitations
Different tags DON'T equal different key namespaces. Tagged and non-tagged items use the same key sequence. Ensure keys are unique - tags only tag, not alter keys. E.g.:
Cache::tags(["tag1", "tag2"])->put("key", "value1"); /** This overwrites the key above since there is a shared tag. */ Cache::tags(["tag2"])->put("key", "value2"); Cache::tags(["tag1"])->get("key"); //Will result in "value2" Cache::get("key"); //Will result in "value2"
Installation
Please read the Limitations section before use as this can have breaking changes. The package can be installed using:
composer require byerikas/cache-tags
To use the new driver - edit your config/cache.php and under stores.YOUR_STORE.driver set the value to redis-tags, and run php artisan optimize.
It's recommended to have a scheduled command that would prune your stale tags to clean up memory. The command is php artisan cache:prune-stale-tags, and should come with Laravel out of the box.
To prevent any memory issues use Redis/Valkey maxmemory-policy of volatile-*.
byerikas/cache-tags 适用场景与选型建议
byerikas/cache-tags 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.67k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2024 年 12 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「cache」 「tags」 「laravel」 「valkey」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 byerikas/cache-tags 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 byerikas/cache-tags 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 byerikas/cache-tags 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
A powerfull cacher based on laravels file cache driver
Microservice RPC through message queues.
Phalcon PHP Meta tags service
The CodeIgniter Redis package
贝嘟分布式缓存扩展
统计信息
- 总下载量: 19.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-03