desarrolla2/cache
Composer 安装命令:
composer require desarrolla2/cache
包简介
Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported.
README 文档
README
A simple cache library, implementing the PSR-16 standard using immutable objects.
Caching is typically used throughout an applicatiton. Immutability ensure that modifying the cache behaviour in one location doesn't result in unexpected behaviour due to changes in unrelated code.
Desarolla2 Cache aims to be the most complete, correct and best performing PSR-16 implementation available.
Installation
composer require desarrolla2/cache
Usage
use Desarrolla2\Cache\Memory as Cache; $cache = new Cache(); $value = $cache->get('key'); if (!isset($value)) { $value = do_something(); $cache->set('key', $value, 3600); } echo $value;
Adapters
The following implementation allows you to combine cache adapters.
Options
You can set options for cache using the withOption or withOptions method.
Note that all cache objects are immutable, setting an option creates a new
object.
TTL
All cache implementations support the ttl option. This sets the default
time (in seconds) that cache will survive. It defaults to one hour (3600
seconds).
Setting the TTL to 0 or a negative number, means the cache should live forever.
Methods
PSR-16 methods
Each cache implementation has the following Psr\SimpleCache\CacheInterface
methods:
get(string $key [, mixed $default])
Retrieve the value corresponding to a provided key
has(string $key)
Retrieve the if value corresponding to a provided key exist
set(string $key, mixed $value [, int $ttl])
Add a value to the cache under a unique key
delete(string $key)
Delete a value from the cache
clear()
Clear all cache
getMultiple(array $keys)
Obtains multiple cache items by their unique keys
setMultiple(array $values [, int $ttl])
Persists a set of key => value pairs in the cache
deleteMultiple(array $keys)
Deletes multiple cache items in a single operation
Additional methods
The Desarrolla2\Cache\CacheInterface also has the following methods:
withOption(string $key, string $value)
Set option for implementation. Creates a new instance.
withOptions(array $options)
Set multiple options for implementation. Creates a new instance.
getOption(string $key)
Get option for implementation.
Packers
Cache objects typically hold a Desarrolla2\Cache\Packer\PackerInterface
object. By default, packing is done using serialize and unserialize.
Available packers are:
SerializePackerusingserializeandunserializeJsonPackerusingjson_encodeandjson_decodeNopPackerdoes no packingMongoDBBinaryPackerusingserializeandunserializeto store as BSON Binary
PSR-16 incompatible packers
The JsonPacker does not fully comply with PSR-16, as packing and
unpacking an object will probably not result in an object of the same class.
The NopPacker is intended when caching string data only (like HTML output) or
if the caching backend supports structured data. Using it when storing objects
will might give unexpected results.
Contributors
Twitter: @desarrolla2
Twitter: @ArnoldDaniels
desarrolla2/cache 适用场景与选型建议
desarrolla2/cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.53M 次下载、GitHub Stars 达 134, 最近一次更新时间为 2012 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「file」 「memcache」 「cache」 「mysql」 「apc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 desarrolla2/cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 desarrolla2/cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 desarrolla2/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 file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
The CodeIgniter Redis package
Pop Cache Component for Pop PHP Framework
统计信息
- 总下载量: 2.53M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 147
- 点击次数: 41
- 依赖项目数: 55
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2012-09-05
