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);
    }