3

By specifying the TTL, the item should be aged out of the cache. But it is not working. This is very very simple. the TTL is set to 1 second. Have I made a mistake?

My version;

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

My script;

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);

Output;

php apcu.php
Not in store, adding
In Store
string(15) "Hello Big Daddy"
In Store
string(15) "Hello Big Daddy"

I do not think the item should be in the Cache on the second call.

But even if someone said it should, then it should certainly not be in the Cache on the third call.

Peter Prographo
  • 1,141
  • 1
  • 10
  • 27

1 Answers1

2

When apc.use_request_time is set to true, which is the default, this is what happens -- the SAPI request start time is used for TTL calculations, not the time each function is called.

David Sickmiller
  • 1,145
  • 8
  • 8