(PECL yac >= 1.0.0)
Yac::set — Store a value into the cache
Stores a value in the cache. If the key already exists, the existing entry is overwritten, regardless of whether it has expired.
key
A string key, or an array of
key => value pairs to store in one call.
value
The value to store. Every PHP type except resource can
be stored. Only used in the single-key form; when
key is an array, this argument is instead the
optional ttl.
ttl
Time to live in seconds. 0 means the entry never
expires by time.
Beispiel #1 Yac::set() example
<?php
$yac = new Yac();
$yac->set("foo", "bar"); // store a single value
$yac->set("foo", "baz"); // overwrite the existing entry
?>Beispiel #2 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
?>Beispiel #3 Setting multiple entries at once
<?php
$yac = new Yac();
// store several key => value pairs with one call
$yac->set(array("a" => 1, "b" => 2));
?>