本文整理汇总了PHP中ElggMemcache::setDefaultExpiry方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggMemcache::setDefaultExpiry方法的具体用法?PHP ElggMemcache::setDefaultExpiry怎么用?PHP ElggMemcache::setDefaultExpiry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggMemcache
的用法示例。
在下文中一共展示了ElggMemcache::setDefaultExpiry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_metadata_byname
/**
* Return the metadata values that match your query.
*
* @param string $meta_name
* @return mixed either a value, an array of ElggMetadata or false.
*/
function get_metadata_byname($entity_guid, $meta_name)
{
global $CONFIG;
$meta_name = get_metastring_id($meta_name);
if (empty($meta_name)) {
return false;
}
$entity_guid = (int) $entity_guid;
$access = get_access_sql_suffix("e");
$md_access = get_access_sql_suffix("m");
// If memcache is available then cache this (cache only by name for now since this is the most common query)
$meta = null;
static $metabyname_memcache;
if (!$metabyname_memcache && is_memcache_available()) {
$metabyname_memcache = new ElggMemcache('metabyname_memcache');
}
if ($metabyname_memcache) {
$meta = $metabyname_memcache->load("{$entity_guid}:{$meta_name}");
}
if ($meta) {
return $meta;
}
$result = get_data("SELECT m.*, n.string as name, v.string as value from {$CONFIG->dbprefix}metadata m JOIN {$CONFIG->dbprefix}entities e ON e.guid = m.entity_guid JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id JOIN {$CONFIG->dbprefix}metastrings n on m.name_id = n.id where m.entity_guid={$entity_guid} and m.name_id='{$meta_name}' and {$access} and {$md_access}", "row_to_elggmetadata");
if (!$result) {
return false;
}
// Cache if memcache available
if ($metabyname_memcache) {
if (count($result) == 1) {
$r = $result[0];
} else {
$r = $result;
}
$metabyname_memcache->setDefaultExpiry(3600);
// This is a bit of a hack - we shorten the expiry on object metadata so that it'll be gone in an hour. This means that deletions and more importantly updates will filter through eventually.
$metabyname_memcache->save("{$entity_guid}:{$meta_name}", $r);
}
if (count($result) == 1) {
return $result[0];
}
return $result;
}