g4/mcache

mcache PHP库

2.1.0 2024-04-18 07:47 UTC

README

mcache - php 缓存包装库

安装

通过composer 包管理器安装。在packagist上查找。

composer require g4/mcache

支持的缓存系统

使用方法

Memcached实例

<?php
    
$driverName = 'Libmemcached';
$options = array(
    'servers' => array(
        '127.0.0.1:11211'
    );
);
$prefix = 'my_prefix';
    
$mcache = \G4\Mcache\McacheFactory::createInstance($driverName, $options, $prefix);

Couchbase实例

<?php
    
$driverName = 'Couchbase';
$options = array(
    'bucket' => 'my_bucket',
    'servers' => array(
        '127.0.0.1:8091'
    );
);
$prefix = 'my_prefix';
    
$mcache = \G4\Mcache\McacheFactory::createInstance($driverName, $options, $prefix);

可用选项

* bucket - string
* servers - array
* user - string
* pass - string
* persistent - bool
* timeout - int (default 2500000)

方法

<?php
    
// Get from cache
$value = $mcache
    ->key('my_key')
    ->get();
    
// Save to cache
$mcache
    ->key('my_key')
    ->value('my_value')
    ->set();
    
// Sava to cache with expiration
$mcache
    ->key('my_key')
    ->value('my_value')
    ->expiration(3600) // in seconds (default 0)
    ->set();
    
// Delete from cache
$mcache
    ->key('my_key')
    ->delete();
    
// Replace a value
$mcache
    ->key('my_key')
    ->value('my_value')
    ->replace();

开发

安装依赖项

$ make install

运行测试

$ make test

许可协议

(MIT许可协议) 详细信息请参阅LICENSE文件...