定制 itsoneiota/cache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

itsoneiota/cache

Composer 安装命令:

composer require itsoneiota/cache

包简介

One iota Cache library.

关键字:

README 文档

README

Overview

A simple interface to cache sources.

The Cache class wraps a Memcached instance, adding key and value mapping, and default expiry times.

Installation

The best way to autoload this package and its dependencies is to include the standard Composer autoloader, vendor/autoload.php.

Testing

The library's suite of unit tests can be run by calling vendor/bin/phpunit from the root of the repository.

Basic Usage

use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new Cache($mc);

$cache->set('foo', 'bar'); // Caches a value of 'bar' against the key of 'foo'.
$cache->get('foo'); // Returns 'bar'.

Prefixing Cache Keys

If you wish to avoid cache key collisions, you can initialise your cache with a key prefix, this will be added to all keys when getting, setting and deleting. For example:

use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new Cache($mc, 'myStore');

$cache->set('foo', 'bar'); // Caches a value of 'bar' against the key of 'myStore.foo'.
$cache->get('foo'); // Returns 'bar'.

Default Expiry Times

When creating a cache, you can specify a default time to live that can be used when adding and setting. This can be overridden when adding and setting by specifying an explicit expiry time.

use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new Cache($mc, 'myStore', 120);

$cache->set('foo', 'bar'); // Caches for 2 minutes (the default).
$cache->set('bat', 'baz', 30); // Caches for 30 seconds.

Encrypting Cache Contents

SecureCache is a subclass of Cache that encrypts its contents using two-way encryption.

use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new SecureCache($mc, 'myTopSecretEncryptionKey');

If you need to prefix keys in SecureCache, you can always call $cache->setKeyPrefix('myPrefix').

Bonus Caches (Cacheback)

InMemoryCacheFront

If you're likely to make several calls to a cache within a request, possibly to the same value, InMemoryCacheFront can prevent unnecessary network calls to the Memcached server, by providing a read- and write-through cache on top of a Cache instance. The number of items held in memory is limited to 100 by default, but that can be changed with a constructor argument.

use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new Cache($mc, 'myStore', 120);

$superFastCache = new InMemoryCacheFront($cache, 1000); // Store 1000 items in local memory.

InMemoryCache

If you need to simulate a cache, without a Memcached server, InMemoryCache will do the job. It looks just like a Cache, but it holds everything in a plain-old PHP array.

MockCache

For testing purposes, MockCache simulates a cache, and allows you to check that values have been set, and what their expiry times are, without having to go through all the hassle of using PHPUnit mocks. getExpiration() allows you to check the expiration of a key. timePasses() allows you to simulate the passage of time, advancing by a given number of seconds and expiring cache items accordingly.

use \itsoneiota\cache;

$cache = new MockCache();

$cache->set('foo', 'bar', 60);
$cache->get('foo'); // Returns 'bar'.

$cache->timePasses(61);

$cache->get('foo'); // Returns NULL.

To Do…

Things I might add, soon-ish:

  • Check-and-set operations
  • Cache pile-on prevention

itsoneiota/cache 适用场景与选型建议

itsoneiota/cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.34k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cache」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 itsoneiota/cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 itsoneiota/cache 我们能提供哪些服务?
定制开发 / 二次开发

基于 itsoneiota/cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2015-10-24