rundiz/simple-cache
Composer 安装命令:
composer require rundiz/simple-cache
包简介
The simple and easy PHP cache drivers for cache any PHP data type.
README 文档
README
The simple and easy PHP cache drivers for cache any PHP data type. It is implemented PSR-16.
Tested up to PHP 8.5.
Installation
Make sure that you have Composer installed and then run the following command.
composer require rundiz/simple-cache
Example
We currently support APC, APCu, Memcache, Memcached, File system drivers. These are how to initialize for each driver class.
// For Memcache driver $memcache = new \Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $SimpleCache = new \Rundiz\SimpleCache\Drivers\Memcached($memcache); unset($memcache); // For Memcached driver $memcached = new \Memcached; $memcached->addServer('localhost', 11211) or die ("Could not connect"); $SimpleCache = new \Rundiz\SimpleCache\Drivers\Memcached($memcached); unset($memcached); // For APC (deprecated, use APCu instead). $SimpleCache = new \Rundiz\SimpleCache\Drivers\Apc(); // For APCu $SimpleCache = new \Rundiz\SimpleCache\Drivers\Apcu(); // For File system (very basic cache driver) $SimpleCache = new \Rundiz\SimpleCache\Drivers\FileSystem(); // For memory cache (This is using PHP array, if class was unset everything will be removed) $SimpleCache = new \Rundiz\SimpleCache\Drivers\Memory();
Common methods to get, set, delete, or anything else please read more at PSR-16 document.
Examples.
// To get or fetch cache data. $SimpleCache->get('cache_key'); // To get multiple cache data. $SimpleCache->getMultiple(['cache_key1', 'cache_key2']); // To check cache exists. $SimpleCache->has('cache_key'); // To save cache data. $SimpleCache->set('cache_key', 'cache data. (any type of data... string, integer, double, array, object, etc.)', 90); // To save multiple cache data. $SimpleCache->setMultiple([ 'cache_key1' => 'string value', 'cache_key2' => 12345, ], 90); // To delete cache. $SimpleCache->delete('cache_key'); // To delete multiple cache. $SimpleCache->deleteMultiple(['cache_key1', 'cache_key2']); // To clear all cached. $SimpleCache->clear();
Fallback cache drivers
You can set many cache drivers as fallback in case that some driver is not installed on the server.
if (class_exists('\\Memcached')) { $memcached = new \Memcached; $memcached->addServer('localhost', 11211) or die ("Could not connect"); $SimpleCache = new \Rundiz\SimpleCache\Drivers\Memcached($memcached); unset($memcached); } elseif (class_exists('\\Memcache')) { $memcache = new \Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $SimpleCache = new \Rundiz\SimpleCache\Drivers\Memcached($memcache); unset($memcache); } elseif (function_exists('apcu_fetch')) { $SimpleCache = new \Rundiz\SimpleCache\Drivers\Apcu(); } else { $SimpleCache = new \Rundiz\SimpleCache\Drivers\FileSystem(); }
Namespace/Sub folders for file system cache
In file system cache, you can use namespace or sub folders by just add "." (dot) to the cache id.
For example: $SimpleCache->set('Model.Accounts.id1', $userdata, 120);.
This will save the cache file to Model/Accounts/id1 folder.
rundiz/simple-cache 适用场景与选型建议
rundiz/simple-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 138 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「memcache」 「cache」 「apc」 「memcached」 「php cache」 「apcu」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rundiz/simple-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rundiz/simple-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rundiz/simple-cache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Simple to use mutex implementation that can use flock, memcache, memcached, mysql or redis for locking
Graphic stand-alone administration for memcached to monitor and debug purpose
Pop Cache Component for Pop PHP Framework
Laravel 5 - Repositories to the database layer
coroutine memcache pool
统计信息
- 总下载量: 138
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-12