3

通过指定 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"

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

但是即使有人说应该,那么肯定也不应该在Cache上第三次调用。

4

1 回答 1

2

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

于 2017-08-01T22:41:21.960 回答