2016-10-20 43 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計算,而不是每個函數被調用的時間。