承接 byerikas/cache-tags 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

byerikas/cache-tags

最新稳定版本:2.0.4

Composer 安装命令:

composer require byerikas/cache-tags

包简介

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

README 文档

README

tests Status Packagist Version GitHub License

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-*.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-03