cache::set PHP Method

set() public method

public set ( $key, $data )
    function set($key, $data)
    {
        $dir = c::get('cache.dir');
        if (!is_dir($dir) or !is_writable($dir)) {
            return false;
        }
        $cache_path = self::name($key);
        if (!($fp = fopen($cache_path, 'wb'))) {
            return false;
        }
        if (flock($fp, LOCK_EX)) {
            fwrite($fp, serialize($data));
            flock($fp, LOCK_UN);
        } else {
            return false;
        }
        fclose($fp);
        @chmod($cache_path, 0777);
        return true;
    }

Usage Example

Beispiel #1
0
 private static function init()
 {
     if (self::$keys == '') {
         if (!(self::$keys = cache::get('global-settings'))) {
             $sql = 'SELECT SQL_CACHE r_id id, r_section_id section, r_key name, r_value value, r_description description FROM <<register>>;';
             self::$keys = db::q($sql, records);
             if (db::issetError()) {
                 die;
             }
             // Записываем в кэш
             cache::set('global-settings', self::$keys);
         }
     }
 }
All Usage Examples Of cache::set