2016-10-20 39 views
2

通过指定TTL,该项目应该超出缓存时间。但它不起作用。这非常非常简单。 TTL设置为1秒。我犯了一个错误吗?APCu TTL不工作php 7.0

我的版本;

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" 

我不认为该项目应在第二次调用缓存中。

但即使有人说应该,那么它肯定不会在第三次调用Cache的时候。

回答

1

当apc.use_request_time设置为true(默认值)时,会发生什么情况 - SAPI请求开始时间用于TTL计算,而不是每个函数被调用的时间。