setDefaultExpiry() 공개 메소드

Set the default TTL.
public setDefaultExpiry ( integer $ttl ) : void
$ttl integer The TTL in seconds from now. Default is no expiration.
리턴 void
예제 #1
0
파일: metadata.php 프로젝트: eokyere/elgg
/**
 * 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;
}