note 110121 added to function.apc-store
| From: | MaxTheDragon at home dot nl | Date: | Fri, 21 Sep 2012 13:39:32 +0000 |
| Subject: | note 110121 added to function.apc-store | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190949@lists.php.net to get a copy of this message | ||
When specifying a ttl (Time-To-Live), you are allowed to use negative values. This causes a stored
entry to be invalidated immediately, but note that it will not physically be removed until you read
(eg. apc_fetch or apc_exists) it:
<?php
apc_store('testKey', 'testValue', -1); // ... or any negative integer.
// at this point, the key exists physically but is already technically invalidated by the ttl.
$test = apc_fetch('testKey'); // $test equals false.
// at this point, the key no longer exists physically.
?>
Although you could mimic apc_delete with a negative TTL (like when dealing with cookies), note that
the difference is that apc_delete actually physically removes the entry.
This example comes in handy when you want to unit-test a class that uses APC. It's faster to
use a negative TTL than a positive in combination with a sleep call to test whether the cache entry
has actually been deleted. Other than that I can't think of any situations in which you could
use this example, but I'm simply pointing out that doing this will not generate Exceptions or
errors.
----
Server IP: 83.137.20.135
Probable Submitter: 87.195.224.218
----
Manual Page -- http://www.php.net/manual/en/function.apc-store.php
Edit -- https://master.php.net/note/edit/110121
Del: integrated -- https://master.php.net/note/delete/110121/integrated
Del: useless -- https://master.php.net/note/delete/110121/useless
Del: bad code -- https://master.php.net/note/delete/110121/bad+code
Del: spam -- https://master.php.net/note/delete/110121/spam
Del: non-english -- https://master.php.net/note/delete/110121/non-english
Del: in docs -- https://master.php.net/note/delete/110121/in+docs
Del: other reasons-- https://master.php.net/note/delete/110121
Reject -- https://master.php.net/note/reject/110121
Search -- https://master.php.net/manage/user-notes.php