承接 ride/lib-cache 相关项目开发

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

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

ride/lib-cache

最新稳定版本:1.3

Composer 安装命令:

composer require ride/lib-cache

包简介

Cache library of the Ride framework.

README 文档

README

Cache library of the PHP Ride framework.

What's In This Library

CacheItem

A CacheItem is the container of your cached value. The implementation contains the logic to see if the cached item is valid and not stale.

An extension to tag your cache items is available through the TaggableCacheItem interface.

The GenericCacheItem class implements both interfaces.

CachePool

A CachePool is the backend or storage of your cache items. The implementation decides how to store your cache items. Each implementation has it's advantages and disadvantages. Your choice should depend on the context of cache usage and server environment.

Available implementations (all implement taggable cache items):

  • ride\library\cache\pool\ApcCachePool: APC implementation
  • ride\library\cache\pool\DirectoryCachePool: Cache directory with one file per cached item
  • ride\library\cache\pool\FileCachePool: One file for the complete pool
  • ride\library\cache\pool\MemcacheCachePool: Memcache implementation
  • ride\library\cache\pool\XCacheCachePool: XCache implementation

CacheControl

A CacheControl provides an interface to expose the management of your caches to the UI.

Code Sample

Check the following code sample to see how the cache should be used:

<?php

use ride\library\cache\pool\DirectoryCachePool;
use ride\library\system\System;

function foo(System $system) {
    // cache initialization
    $cacheDirectory = $system->getFileSystem()->getFile('/path/to/cache');
    $cachePool = new DirectoryCachePool($cacheDirectory);

    // cache usage
    $cacheItem = $cachePool->get('item.cache.key');
    if (!$cacheItem->isValid()) {
        // some value generation logic
        // ...

        // store value to the cache
        $cacheItem->setValue($value); // required
        $cacheItem->setTtl(60); // in seconds, optional
        $cacheItem->setTag('section'); // you can tag an item, optional

        $cachePool->set($cacheItem);
    } else {
        // retrieve value from cache
        $value = $cacheItem->getValue();
    }

    // cache flush
    $cachePool->flush(); // flush complete cache
    $cachePool->flush('item.cache.key'); // remove an item
    $cachePool->flushByTag('section'); // remove all items tagged with section
}

This code uses the item as returned from the pool to set the cached value.

When you warm up your cache in another place, you can easily create your cache item through the pool:

<?php

use ride\library\cache\pool\CachePool;

function bar(CachePool $cachePool) {
    $cacheItem = $cachePool->create('item.cache.key');
    $cacheItem->setValue('some cache value');

    $cachePool->set($cacheItem);
}

Installation

You can use Composer to install this library.

composer require ride/lib-cache

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-21