rickysu/tagcache

提供缓存存储引擎和带标签的删除功能

v1.0.3 2015-07-02 13:04 UTC

This package is auto-updated.

Last update: 2024-09-14 18:14:54 UTC


README

Build Status

介绍

这是一个缓存存储引擎。

特性

  • 使用多个标签存储缓存。并使用标签删除缓存。

要求

  • PHP 5.3 以上

安装

编辑根项目中的 composer.json 文件。

在 require: {} 部分编辑 composer.json 添加

"rickysu/tagcache": "0.1.*",

更新 Composer

php composer.phar update

驱动

缓存驱动。目前支持 "Memcache,Memcached,File,Sqlite,Apc,Nullcache"。Nullcache 仅用于测试。

hashkey

某些驱动如 Memcached 仅支持 250 个字符的键长度。启用此选项将使用 md5 哈希键。

enable_largeobject

Memcache 无法存储超过 1MB 的对象。启用这些选项将修复此问题,但会降低性能。默认为 false。

servers

Memcache 服务器配置。格式 => "Host:Port:Weight"

如何使用

使用 Tagcache 存储数据。

<?php
use RickySu\Tagcache\TagcacheFactory;

$Tagcache=TagcacheFactory::factory(array(
    'driver'   => 'Memcache',
    'namespace' => 'Name_Space_For_Your_Project',
    'options'   => array(
        'hashkey'  => true,
        'enable_largeobject'  =>    false,
        'cache_dir'  =>  'Temp_Cache_File_Store_Path',
        'servers'    => array(
            'localhost:11211:10',
            'otherhost:11211:20',
        ),
    ),    
));

//store cache with Tags:{TagA,TagB} for 300 secs.
$Tagcache->set('Key_For_Store','Data_For_Store',array('TagA','TagB'),300);

//get cache.
$Tagcache->get('Key_For_Store');

//delete cache.
$Tagcache->delete('Key_For_Store');

//delete cache by Tag.
$Tagcache->deleteTag('TagA');

//acquire a lock.If a lock already exists,It will be blocked for 5 secs.
$Tagcache->getLock('Your_Lock_Name',5);

//release a lock.
$Tagcache->releaseLock('Your_Lock_Name');

//increment a cache
$Tagcache->inc('Key_For_increment');

//decrement a cache
$Tagcache->dec('Key_For_decrement');

TODO
----


LICENSE
-------

MIT