通过指定TTL,项应该从缓存中老化。但这并没有奏效。这非常非常简单。TTL设置为1秒。我错了吗?
我的版本;
PHP 7.0.12-1+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.12-1+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies
我的脚本;
cat apcu.php
<?php
$key="KEY";
function xxx($key) {
if (apcu_exists($key)) {
print ("In Store'n");
$value = apcu_fetch($key);
var_dump($value);
} else {
$value = "Hello Big Daddy";
apcu_add($key, $value, 1);
print ("Not in store, adding'n");
}
}
xxx($key);
sleep(2);
xxx($key);
sleep(3);
xxx($key);
输出;
php apcu.php
Not in store, adding
In Store
string(15) "Hello Big Daddy"
In Store
string(15) "Hello Big Daddy"
我不认为第二次调用时该项目应该在缓存中。
但是即使有人说它应该,那么它肯定不应该在第三次调用时出现在缓存中。
当apc。use_request_time被设置为true,这是默认的,这就是发生的事情——SAPI请求开始时间用于TTL计算,而不是每个函数被调用的时间。