(PECL yac >= 1.0.0)
Yac::get — Retrieve values from cache
Retrieve values from cache
keydefault
The value to return when the requested key (or keys) is not
present in the cache, available as of yac 2.4.0. When omitted, a
miss returns false.
Hinweis:
Before yac 2.4.0, this argument slot held a by-reference
$castoken rather than a default value. Code that passed or relied on that token must be updated when upgrading to 2.4.0.
For a string key, returns the cached value on a hit,
otherwise the default (or false when no default
was given).
For an array of keys, returns an array containing the
found values indexed by their keys. Keys that are not present in
the cache are omitted from the result as of yac 2.4.0, or filled
with the default when one was given; before
2.4.0, a false placeholder was inserted for every missing key.
Beispiel #1 Yac::get() example
<?php
$yac = new Yac();
$yac->set("foo", "bar");
var_dump($yac->get("foo")); // string(3) "bar"
var_dump($yac->get("missing")); // bool(false): a miss
?>Beispiel #2 Telling a stored false apart from a miss
<?php
$yac = new Yac();
// a miss and a stored false are indistinguishable without a default;
// a sentinel default (available as of yac 2.4.0) tells them apart
$yac->set("flag", false);
var_dump($yac->get("flag")); // bool(false): the stored value
var_dump($yac->get("missing", false)); // bool(false): a miss, same shape
var_dump($yac->get("flag", "__NONE__")); // bool(false): the stored value
var_dump($yac->get("missing", "__NONE__")); // string(8) "__NONE__": a miss
?>Beispiel #3 Getting multiple keys at once
<?php
$yac = new Yac();
$yac->set("foo", "bar");
$yac->set("foo2", "bar2");
// with an array of keys, only the found keys are present in the result
var_dump($yac->get(array("foo", "foo2", "missing")));
// array(2) { ["foo"]=> string(3) "bar" ["foo2"]=> string(4) "bar2" }
?>