protected static function set_cache($fn, $cnt, $meta = null, $gzip = true)
    {
        if (false === $cnt) {
            return !file_exists($fn) || unlink($fn);
        }

        $n = 0;
        if (isset($meta)) {
            $meta = self::jsonize($meta);
            $n += strlen($meta);
        }
        $meta = '#' . $n . "\n" . $meta;
        if (!is_string($cnt) || "\n" == $cnt[0]) {$cnt = "\n" . self::jsonize($cnt); ++$n;}
        if ($n) {
            $cnt = $meta . $cnt;
        }

        unset($meta);
        if ($gzip) {
            $gl = is_int($gzip) ? $gzip : 1024;
            // Cache as gzip only if built-in gzdecode() defined (more CPU for less IO)
            strlen($cnt) > $gl && self::gz_supported() and
            $cnt = gzencode($cnt);
        }
        file_exists($dn = dirname($fn)) or mkdir($dn, 0777, true);
        return self::flock_put_contents($fn, $cnt);
    }
protected static function set_cache($fn, $cnt, $meta = null, $gzip = true)
    {
        if (false === $cnt) {
            return !file_exists($fn) || unlink($fn);
        }

        $n = 0;
        if (isset($meta)) {
            $meta = self::jsonize($meta);
            $n += strlen($meta);
        }
        $meta = '#' . $n . "\n" . $meta;
        if (!is_string($cnt) || "\n" == $cnt[0]) {$cnt = "\n" . self::jsonize($cnt); ++$n;}
        if ($n) {
            $cnt = $meta . $cnt;
        }

        unset($meta);
        if ($gzip) {
            $gl = is_int($gzip) ? $gzip : 1024;
            // Cache as gzip only if built-in gzdecode() defined (more CPU for less IO)
            strlen($cnt) > $gl && self::gz_supported() and
            $cnt = gzencode($cnt);
        }
        file_exists($dn = dirname($fn)) or mkdir($dn, 0777, true);
        return self::flock_put_contents($fn, $cnt);
    }
protected static function set_cache ( $ fn , $ cnt , $ meta = null , $ gzip = true ) { if ( false === $ cnt ) { return ! file_exists ( $ fn ) || unlink ( $ fn ) ; } $ n = 0 ; if ( isset ( $ meta ) ) { $ meta = self :: jsonize ( $ meta ) ; $ n += strlen ( $ meta ) ; } $ meta = '#' . $ n . "\n" . $ meta ; if ( ! is_string ( $ cnt ) || "\n" == $ cnt [ 0 ] ) { $ cnt = "\n" . self :: jsonize ( $ cnt ) ; ++ $ n ; } if ( $ n ) { $ cnt = $ meta . $ cnt ; } unset ( $ meta ) ; if ( $ gzip ) { $ gl = is_int ( $ gzip ) ? $ gzip : 1024 ; // Cache as gzip only if built-in gzdecode() defined (more CPU for less IO) strlen ( $ cnt ) > $ gl && self :: gz_supported ( ) and $ cnt = gzencode ( $ cnt ) ; } file_exists ( $ dn = dirname ( $ fn ) ) or mkdir ( $ dn , 0777 , true ) ; return self :: flock_put_contents ( $ fn , $ cnt ) ; }
Save data to a cache file.

@param  string   $fn   - cache filename
@param  mixed    $cnt  - contents to be cached
@param  array    $meta - OPTIONAL meta information related to contents.
@param  bool     $gzip - OPTIONAL if TRUE and gzip supported, store contents gzipped
@return int|bool On success, number of written bytes, FALSE on fail.
Save data to a cache file .