本文整理汇总了PHP中Nette\Caching\Cache::checkCallbacks方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::checkCallbacks方法的具体用法?PHP Cache::checkCallbacks怎么用?PHP Cache::checkCallbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Caching\Cache
的用法示例。
在下文中一共展示了Cache::checkCallbacks方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
* Read from cache.
* @param string key
* @return mixed|NULL
*/
public function read($key)
{
$key = $this->prefix . $key;
$meta = $this->memcache->get($key);
if (!$meta) {
return NULL;
}
// meta structure:
// array(
// data => stored data
// delta => relative (sliding) expiration
// callbacks => array of callbacks (function, args)
// )
// verify dependencies
if (!empty($meta[self::META_CALLBACKS]) && !Cache::checkCallbacks($meta[self::META_CALLBACKS])) {
$this->memcache->delete($key, 0);
return NULL;
}
if (!empty($meta[self::META_DELTA])) {
$this->memcache->replace($key, $meta, 0, $meta[self::META_DELTA] + time());
}
return $meta[self::META_DATA];
}
示例2: read
/**
* Read from cache.
* @param string key
* @return mixed|NULL
*/
public function read($key)
{
$this->_normalizeKey($key);
$meta = apc_fetch($key);
if (!$meta) {
return NULL;
}
// meta structure:
// array(
// data => stored data
// delta => relative (sliding) expiration
// callbacks => array of callbacks (function, args)
// )
// verify dependencies
if (!empty($meta[self::META_CALLBACKS]) && !Cache::checkCallbacks($meta[self::META_CALLBACKS])) {
apc_delete($key);
return NULL;
}
if (!empty($meta[self::META_DELTA])) {
apc_delete($key);
apc_store($key, $meta, 0, $meta[self::META_DELTA] + time());
}
return $meta[self::META_DATA];
}
示例3: verify
/**
* Verifies dependencies.
* @param array
* @return bool
*/
private function verify($meta)
{
do {
if (!empty($meta[self::META_DELTA])) {
// meta[file] was added by readMetaAndLock()
if (filemtime($meta[self::FILE]) + $meta[self::META_DELTA] < time()) {
break;
}
touch($meta[self::FILE]);
} elseif (!empty($meta[self::META_EXPIRE]) && $meta[self::META_EXPIRE] < time()) {
break;
}
if (!empty($meta[self::META_CALLBACKS]) && !Cache::checkCallbacks($meta[self::META_CALLBACKS])) {
break;
}
if (!empty($meta[self::META_ITEMS])) {
foreach ($meta[self::META_ITEMS] as $depFile => $time) {
$m = $this->readMetaAndLock($depFile, LOCK_SH);
if ($m[self::META_TIME] !== $time || $m && !$this->verify($m)) {
break 2;
}
}
}
return TRUE;
} while (FALSE);
$this->delete($meta[self::FILE], $meta[self::HANDLE]);
// meta[handle] & meta[file] was added by readMetaAndLock()
return FALSE;
}
示例4: read
function read($key)
{
$key = $this->prefix . $key;
$meta = $this->memcache->get($key);
if (!$meta) {
return NULL;
}
if (!empty($meta[self::META_CALLBACKS]) && !Cache::checkCallbacks($meta[self::META_CALLBACKS])) {
$this->memcache->delete($key, 0);
return NULL;
}
if (!empty($meta[self::META_DELTA])) {
$this->memcache->replace($key, $meta, 0, $meta[self::META_DELTA] + time());
}
return $meta[self::META_DATA];
}
示例5: verify
/**
* Verifies dependencies.
*
* @param array
*
* @return bool
*/
protected function verify($meta)
{
do {
if (!empty($meta[self::META_DELTA])) {
$this->client->send('expire', [$this->formatEntryKey($meta[self::KEY]), $meta[self::META_DELTA]]);
} elseif (!empty($meta[self::META_EXPIRE]) && $meta[self::META_EXPIRE] < time()) {
break;
}
if (!empty($meta[self::META_CALLBACKS]) && !Cache::checkCallbacks($meta[self::META_CALLBACKS])) {
break;
}
if (!empty($meta[self::META_ITEMS])) {
foreach ($meta[self::META_ITEMS] as $itemKey => $time) {
$m = $this->readMeta($itemKey);
if ($m[self::META_TIME] !== $time || $m && !$this->verify($m)) {
break 2;
}
}
}
return TRUE;
} while (FALSE);
$this->remove($meta[self::KEY]);
// meta[handle] & meta[file] was added by readMetaAndLock()
return FALSE;
}
示例6: bulkRead
/**
* Reads from cache in bulk.
* @param string key
* @return array key => value pairs, missing items are omitted
*/
public function bulkRead(array $keys)
{
$prefixedKeys = array_map(function ($key) {
return urlencode($this->prefix . $key);
}, $keys);
$keys = array_combine($prefixedKeys, $keys);
$metas = $this->memcached->getMulti($prefixedKeys);
$result = [];
$deleteKeys = [];
foreach ($metas as $prefixedKey => $meta) {
if (!empty($meta[self::META_CALLBACKS]) && !Cache::checkCallbacks($meta[self::META_CALLBACKS])) {
$deleteKeys[] = $prefixedKey;
} else {
$result[$keys[$prefixedKey]] = $meta[self::META_DATA];
}
if (!empty($meta[self::META_DELTA])) {
$this->memcached->replace($prefixedKey, $meta, $meta[self::META_DELTA] + time());
}
}
if (!empty($deleteKeys)) {
$this->memcached->deleteMulti($deleteKeys, 0);
}
return $result;
}