henzeb/laravel-cache-index
Composer 安装命令:
composer require henzeb/laravel-cache-index
包简介
Flexible replacement for tags
README 文档
README
When you have a situation where you need to be able to track keys, you can use tags. Unfortunately tags aren't supported by all drivers, and retrieving keys is only doable the hacky way with redis.
Cache Index for Laravel provides a driver-independent way for managing such indexes.
Installation
Just install with the following command.
composer require henzeb/laravel-cache-index
Usage
Under the hood, index returned an extended Illuminate\Cache\Repository
object, which manages your index.
See Laravel doc's for the possible methods.
keys are prefixed with the index name, so that you can't accidentally overwrite any values belonging to that index.
Note: tags are currently not supported when using index.
Cache::index('myIndex')->add('test', 'my value'); Cache::index('myIndex')->put('put', 'my value'); Cache::driver('file')->index('myIndex')->remember('filed', 'my value in file'); Cache::index('myIndex')->get('put'); // returns 'my value' Cache::get('put'); // returns null Cache::index('myIndex')->flush(); // only flushes keys in index
index name
The index name can, next to a regular string, also be applied as an array. This is handy when you have an index based on variables.
Cache::index(['myIndex', 'Read', 'Write']); // uses index name `myIndex.Read.Write` Cache::index(['myIndex', ActionEnum::Read]); // uses index name `myIndex.Read` Cache::index(['myIndex', new StdClass()]); // uses index name `myIndex.StdClass` Cache::index(['myIndex', new StringableClass('stringed')]); // uses index name `myIndex.stringed`
Keys
Retrieving a list of keys is very easy.
Cache::index('myIndex')->keys(); // returns ['test', 'put'] Cache::driver('file')->index('myIndex')->keys(); // returns ['filed']
Count
With this method, you can know how many keys are inside your index.
Cache::index('myIndex'); // using default driver Cache::driver('file')->index('myIndex'); // using file driver
Copy & Move
Copy
Makes a copy of a cached item, and adds the key in the new index.
It returns true if it's successful, false otherwise.
Cache::index('myIndex')->copy('myKey', 'targetIndex'); Cache::index('myIndex')->copy('myKey', 'targetIndex', 10);
Move
Does the same as Copy, except that it removes its own copy.
It returns true if it's successful, false otherwise.
Cache::index('myIndex')->move('myKey', 'targetIndex'); Cache::index('myIndex')->move('myKey', 'targetIndex', 10);
Note: Be aware that either copy and move do nothing with the TTL. It creates a new copy of the cached item with a new TTL if given.
pop
Just like with arrays, takes and removes the last indexed key and returns the value associated with that index.
shift
Just like with arrays, takes and removes the first indexed key and returns the value associated with that index.
random
returns a random value.
randomKey
returns a random key.
pullRandom
Returns a random value and pulls it from the cache.
syncTtl
Allows you to synchronize the ttl between indexed keys.
Cache::index('myIndex')->syncTtl(10); Cache::index('myIndex')->syncTtl(now()->addSeconds(10));
Testing this package
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email henzeberkheij@gmail.com instead of using the issue tracker.
Credits
License
The GNU AGPLv. Please see License File for more information.
henzeb/laravel-cache-index 适用场景与选型建议
henzeb/laravel-cache-index 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.7k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2023 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「laravel」 「index」 「henzeb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 henzeb/laravel-cache-index 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 henzeb/laravel-cache-index 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 henzeb/laravel-cache-index 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Symfony Solr integration bundle
Annotation and command for control entity custom indexes
Laravel Sitemap Generator. Supports SitemapIndex, Images Sitemap and News Sitemap.
Laravel 5 - Repositories to the database layer
Validates Zip/Postal Codes for any country and provides each country's localized name for their version of the Zip/Postal code (CEP, PLZ, PIN code, Eircode, NPA, CAP, ZIP code, etc.).
统计信息
- 总下载量: 15.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-only
- 更新时间: 2023-01-25