cache::get PHP Method

get() public method

public get ( $key, $expires = null )
    function get($key, $expires = null)
    {
        $dir = c::get('cache.dir');
        $expires = $expires == null ? c::get('cache.expires') : $expires;
        if (!is_dir($dir) or !is_writable($dir)) {
            return false;
        }
        $cache_path = self::name($key);
        if (!@file_exists($cache_path)) {
            return false;
        }
        if (filemtime($cache_path) < time() - $expires) {
            self::clear($key);
            return false;
        }
        if (!($fp = @fopen($cache_path, 'rb'))) {
            return false;
        }
        flock($fp, LOCK_SH);
        $data = '';
        if (filesize($cache_path) > 0) {
            $data = unserialize(fread($fp, filesize($cache_path)));
        } else {
            $data = null;
        }
        flock($fp, LOCK_UN);
        fclose($fp);
        return $data;
    }

Usage Example

Beispiel #1
0
function create_pm_header()
{
    global $mod, $config;
    if ($config['cache']['enabled'] && ($header = cache::get('pm_unread_' . $mod['id'])) != false) {
        if ($header === true) {
            return false;
        }
        return $header;
    }
    $query = prepare("SELECT `id` FROM ``pms`` WHERE `to` = :id AND `unread` = 1");
    $query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
    $query->execute() or error(db_error($query));
    if ($pm = $query->fetch(PDO::FETCH_ASSOC)) {
        $header = array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1);
    } else {
        $header = true;
    }
    if ($config['cache']['enabled']) {
        cache::set('pm_unread_' . $mod['id'], $header);
    }
    if ($header === true) {
        return false;
    }
    return $header;
}
All Usage Examples Of cache::get