popphp/pop-cache
Composer 安装命令:
composer require popphp/pop-cache
包简介
Pop Cache Component for Pop PHP Framework
README 文档
README
Overview
pop-cache provides the ability to cache frequently accessed content via several different adapters.
The adapters all share the same interface and are interchangeable. Depending on the server environment
and what's available, an application can use one of the following cache adapters:
- Apc (caching service)
- Memcached (caching service)
- Redis (caching service)
- File (directory on disk)
- Database (database caching)
- Session (short-term caching in session)
pop-cache is a component of the Pop PHP Framework.
Install
Install pop-cache using Composer.
composer require popphp/pop-cache
Or, require it in your composer.json file
"require": {
"popphp/pop-cache" : "^4.0.3"
}
Quickstart
Here is a basic example to create a cache object and then save and retrieve some data from it.
The adapter can be passed a "time-to-live" value in seconds (TTL). If set to 0, then the cached
items will never expire:
use Pop\Cache\Cache; use Pop\Cache\Adapter\File; // Passing the file adapter the location on disk and the TTL $cache = new Cache(new Adapter\File('/path/to/my/cache/dir', 300)); $cache->saveItem('foo', $data); $data = $cache->getItem('foo');
Check if the cache has an item
if $cache->hasItem('foo') { } // Return bool
Delete item
$cache->deleteItem('foo');
Delete items
$cache->deleteItems(['foo', 'bar']);
Clear all items out of the cache
$cache->clear();
APC
Using the APC adapter requires APC to be correctly set up in the environment.
use Pop\Cache\Cache; use Pop\Cache\Adapter\Apc; $cache = new Cache(new Apc(300));
Memcached
Using the Memcached adapter requires Memcached to be correctly set up in the environment.
use Pop\Cache\Cache; use Pop\Cache\Adapter\Memcached; $cache = new Cache(new Memcached(300, 'localhost', 11211));
Redis
Using the Redis adapter requires Redis to be correctly set up in the environment.
use Pop\Cache\Cache; use Pop\Cache\Adapter\Redis; $cache = new Cache(new Redis(300, 'localhost', 6379));
File
Using the file adapter will simply store the cache data on the local disk.
use Pop\Cache\Cache; use Pop\Cache\Adapter\File; $cache = new Cache(new Adapter\File('/path/to/my/cache/dir', 300));
Database
Using the database adapter will require the database to be set up correctly and the use of
the pop-db component.
use Pop\Cache\Cache; use Pop\Cache\Adapter\Database; use Pop\Db\Db; $cache = new Cache( new Database(Db::sqliteConnect(['database' => __DIR__ . '/tmp/cache.sqlite']), 300) );
Session
Using the session adapter will store the cached data in session
use Pop\Cache\Cache; use Pop\Cache\Adapter\Session; $cache = new Cache(new Session(300));
popphp/pop-cache 适用场景与选型建议
popphp/pop-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.31k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2014 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「php」 「memcache」 「cache」 「apc」 「caching」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 popphp/pop-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 popphp/pop-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 popphp/pop-cache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple to use mutex implementation that can use flock, memcache, memcached, mysql or redis for locking
Microservice RPC through message queues.
Graphic stand-alone administration for memcached to monitor and debug purpose
The CodeIgniter Redis package
贝嘟分布式缓存扩展
coroutine memcache pool
统计信息
- 总下载量: 7.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-12-07