Yac::set
(PECL yac >= 1.0.0)
Store a value into the cache
Description
Stores a value in the cache. If the key already exists, the existing entry is overwritten, regardless of whether it has expired.
Parameters
keyA
stringkey, or anarrayofkey => valuepairs to store in one call.valueThe value to store. Every PHP type except
resourcecan be stored. Only used in the single-key form; whenkeyis an array, this argument is instead the optionalttl.ttlTime to live in seconds.
0means the entry never expires by time.
Return Values
Returns true on success, false on failure.
Examples
Yac::set example
<?php
$yac = new Yac();
$yac->set("foo", "bar"); // store a single value
$yac->set("foo", "baz"); // overwrite the existing entry
?>Setting an entry with a TTL
<?php
$yac = new Yac();
// ttl in seconds: the entry expires after 5 seconds
$yac->set("short-lived", "value", 5);
sleep(6);
var_dump($yac->get("short-lived")); // bool(false): expired
?>Setting multiple entries at once
<?php
$yac = new Yac();
// store several key => value pairs with one call
$yac->set(array("a" => 1, "b" => 2));
?>See Also
Yac::addYac::getYac::__set