承接 ds/easy-cache 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ds/easy-cache

Composer 安装命令:

composer require ds/easy-cache

包简介

PHP PSR 16 Caching Component

README 文档

README

psr/simple-cache For more information on PSR-16.

Installation

Use Composer to install the component:

$ composer require ds/easyCache "^v1.0.0"

Usage

Saving to Cache

$cache->set(string $key, mixed $value, DateInterval $expires)
  • $key - string Cache keys must be a valid string.

  • $value - mixed Data to be stored in cache

  • $expires - DateInterval|int|null If null then default expires is used.

$cache->setMultiple($values, DateInterval $expires)
  • $values - traversable values must be provided in key => data format, and must be traversable

Fetching from Cache

$cache->get(string $key, mixed $default = null)
  • $key - string Cache keys must be a valid string.

  • $default - mixed Default value to returned in the event that key doesn't exist.

$cache->getMultiple($values)
  • $values - traversable values must be provided in key => data format, and must be traversable

Checking items in cache Storage

$cache->has(string $key, mixed $default = null)
  • $default - mixed Default value to returned in the event that key doesn't exist.

Removing items from cache Storage

$cache->delete(string $key)
$cache->deleteMultiple(traversable $keys)
  • $keys - array/traversable List of keys to be removed.

Clearing cache Storage

$cache->clear()

Storage Adaptors

The following adaptors are available:

  • Rs\Storage\NullStorage
  • Rs\Storage\FileStorage
  • Rs\Storage\MemcacheStorage
  • Rs\Storage\ApcStorage (no longer supported)

Creating new Adaptors

  • Adaptors must implement Ds\Cache\CacheStorageInterface
  • Adaptors may extend Ds\Cache\Storage\AbstractStorage

Initialise the component:

$cache = new \Ds\Cache\Cache();

NullStorage Adaptor is used by default, the above is the same as:

$cache = new \Ds\Cache\Cache(
    new \Ds\Cache\NullStoage()
);

Change the CacheStorage adaptor:

Update the cache adaptor with Cache::withCacheStorage

Method is immutable and returns a new instance of Ds\Cache

Memcached

Ds\Cache\Storage\MemcacheStorage(
    Memcached $memcache,
    string $server,
    int $port,
    DateInterval $ttl
)
$memcache = $cache->withCacheStorage(
    new \Ds\Cache\Storage\MemcacheStorage(
        new \Memcached(),
        'localhost',
        11211,
        new \DateInterval('P1M')
    )
)

File Storage

Ds\Cache\Storage\FileStorage(
    string $directory,
    DateInterval $ttl
)
$filestorage = $cache->withCacheStorage(
    new \Ds\Cache\Storage\FileStorage(
        __DIR__ . '/cacheDirectory',
        new \DateInterval('P1M')
    )
)

Tests

Use phpunit To execute the test suite Tests/Cache,

$ phpunit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固