git克隆
$ git clone https://github.com/laruence/yac.git
解压安装
注意这里的php-config可能不一样
查看php-config位置
$whereis php
编译安装
$ cd yac
$ phpize
$ ./configure --with-php-config=/usr/bin/php-config
$ make
$ make install
修改php.ini,载入扩展,重启php-fpm
extension = yac.so
yac.enable = 1
yac.keys_memory_size = 4M
yac.values_memory_size = 64M
yac.compress_threshold = -1
yac.enable_cli = 0
# 重启php-fpm
service php-fpm reload
检查是否安装成功
$ php -m
用法
实例化
use Yac
$yac = new Yac();
set
Yac::set($key, $value,$ttl])
Yac::set(array $kvs,$ttl])
$yac->set("foo", "bar");
$yac->set(
array(
"dummy" => "foo",
"dummy2" => "foo",
)
);
get
Yac::get(array|string $key)
$yac->get("dummy");
$yac->get(array("dummy", "dummy2"));
delete
delay表示延迟多少秒删除
Removes a stored variable from the cache. If delay is specified, then the value will be deleted after $delay seconds.
$yac->delete(array|string $keys,$delay=0)
flush
Immediately invalidates all existing items. it doesn't actually free any resources, it only marks all the items as invalid.
$yac->flush()
info
查看chche信息
$yac->info()
我们不一样