cache
composer php cache, (*1)
书写composer.json,内容如下:
{
"require":{
"carler/php_cache":"dev-master",
"php" : ">5.3.0"
},
"minimum-stability":"dev"
} , (*2)
例子:
<?php
require 'vendor/autoload.php';
use CarlerCache\CCache;
$config = [
'file' => [
'path' => '/tmp/'
]
];
$cache = new CCache($config['file'],'file'); , (*3)
$key = 'test';
$value = '12312312';
$ttl = 3; , (*4)
$ret = $cache->set($key, $value, $ttl); , (*5)
if ($ret != 0) {
echo "set success, value is $value \nttl is $ttl \n";
} , (*6)
$ret = $cache->get($key);
if (!empty($ret)) {
echo "get success , value is $ret \n";
} , (*7)
$ret = $cache->delete($key);
if (!file_exists($config['file']['path'] . $key)) {
echo 'delete file success';
} , (*8)
redis参数:
$config = [
'redis' => [
'host' => '127.0.0.1',
'port' => '9001',
'select' => '0',
'password' => 'redis123'
]
]; , (*9)
$cache = new CCache($config['redis'], 'redis'); , (*10)
ssdb参数:
$config = [
'ssdb' => [
'host' => '127.0.0.1',
'port' => '8888',
'password' => '1234567890qwertyuiopasdfghjklzxcvbnm'
]
]; , (*11)
$cache = new CCache($config['ssdb'], 'ssdb'); , (*12)
$cache->get($key); //获取key值
$cache->set($key, $val, $ttl);; //设置key 的value值 ttl是有效期 时间为秒,默认360s
$cache->delete($key) ; //删除key值 , (*13)