本文整理汇总了PHP中false::get方法的典型用法代码示例。如果您正苦于以下问题:PHP false::get方法的具体用法?PHP false::get怎么用?PHP false::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类false
的用法示例。
在下文中一共展示了false::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: has
/**
* Test is a cache has a key.
*
* The use of the has methods is strongly discouraged. In a high load environment the cache may well change between the
* test and any subsequent action (get, set, delete etc).
* Instead it is recommended to write your code in such a way they it performs the following steps:
* <ol>
* <li>Attempt to retrieve the information.</li>
* <li>Generate the information.</li>
* <li>Attempt to set the information</li>
* </ol>
*
* Its also worth mentioning that not all stores support key tests.
* For stores that don't support key tests this functionality is mimicked by using the equivalent get method.
* Just one more reason you should not use these methods unless you have a very good reason to do so.
*
* @param string|int $key
* @param bool $tryloadifpossible If set to true, the cache doesn't contain the key, and there is another cache loader or
* data source then the code will try load the key value from the next item in the chain.
* @return bool True if the cache has the requested key, false otherwise.
*/
public function has($key, $tryloadifpossible = false)
{
$parsedkey = $this->parse_key($key);
if ($this->is_in_persist_cache($parsedkey)) {
return true;
}
if ($this->has_a_ttl() && !$this->store_supports_native_ttl() || !$this->store_supports_key_awareness()) {
if ($this->store_supports_key_awareness() && !$this->store->has($parsedkey)) {
return false;
}
$data = $this->store->get($parsedkey);
if (!$this->store_supports_native_ttl()) {
$has = $data instanceof cache_ttl_wrapper && !$data->has_expired();
} else {
$has = $data !== false;
}
} else {
$has = $this->store->has($parsedkey);
}
if (!$has && $tryloadifpossible) {
if ($this->loader !== false) {
$result = $this->loader->get($parsedkey);
} else {
if ($this->datasource !== null) {
$result = $this->datasource->load_for_cache($key);
}
}
$has = $result !== null;
if ($has) {
$this->set($key, $result);
}
}
return $has;
}
示例2: has
/**
* Test is a cache has a key.
*
* The use of the has methods is strongly discouraged. In a high load environment the cache may well change between the
* test and any subsequent action (get, set, delete etc).
* Instead it is recommended to write your code in such a way they it performs the following steps:
* <ol>
* <li>Attempt to retrieve the information.</li>
* <li>Generate the information.</li>
* <li>Attempt to set the information</li>
* </ol>
*
* Its also worth mentioning that not all stores support key tests.
* For stores that don't support key tests this functionality is mimicked by using the equivalent get method.
* Just one more reason you should not use these methods unless you have a very good reason to do so.
*
* @param string|int $key
* @param bool $tryloadifpossible If set to true, the cache doesn't contain the key, and there is another cache loader or
* data source then the code will try load the key value from the next item in the chain.
* @return bool True if the cache has the requested key, false otherwise.
*/
public function has($key, $tryloadifpossible = false)
{
$parsedkey = $this->parse_key($key);
if ($this->is_in_persist_cache($parsedkey)) {
// Hoorah, that was easy. It exists in the static acceleration array so we definitely have it.
return true;
}
if ($this->has_a_ttl() && !$this->store_supports_native_ttl()) {
// The data has a TTL and the store doesn't support it natively.
// We must fetch the data and expect a ttl wrapper.
$data = $this->store->get($parsedkey);
$has = $data instanceof cache_ttl_wrapper && !$data->has_expired();
} else {
if (!$this->store_supports_key_awareness()) {
// The store doesn't support key awareness, get the data and check it manually... puke.
// Either no TTL is set of the store supports its handling natively.
$data = $this->store->get($parsedkey);
$has = $data !== false;
} else {
// The store supports key awareness, this is easy!
// Either no TTL is set of the store supports its handling natively.
$has = $this->store->has($parsedkey);
}
}
if (!$has && $tryloadifpossible) {
if ($this->loader !== false) {
$result = $this->loader->get($parsedkey);
} else {
if ($this->datasource !== null) {
$result = $this->datasource->load_for_cache($key);
}
}
$has = $result !== null;
if ($has) {
$this->set($key, $result);
}
}
return $has;
}