Exemplo n.º 1
0
 public static function clear($name, $args = array())
 {
     $name = 'Cache::clear::' . $name;
     $hash = Once::clear($name, $args);
     Mem::delete($hash);
     return $hash;
 }
Exemplo n.º 2
0
<?php

namespace infrajs\mem;

use infrajs\mem\Mem;
use infrajs\ans\Ans;
use infrajs\config\Config;
if (!is_file('vendor/autoload.php')) {
    chdir('../../../../');
    require_once 'vendor/autoload.php';
}
$ans = array();
$ans['title'] = 'Проверка доступности сервера';
$conf = Mem::$conf;
if ($conf['type'] != 'mem') {
    $ans['class'] = "bg-warning";
    return Ans::ret($ans, 'memcache не используется config.mem.mem');
}
if (!class_exists('Memcache')) {
    return Ans::err($ans, 'Нет класса Memcache');
}
$mem = Mem::memcache();
if (!$mem) {
    return Ans::err($ans, 'Сервер не доступен');
}
Mem::set('test', true);
$val = Mem::get('test');
if (!$val) {
    return Ans::err($ans, 'Неудалось восстановить значение. Требуется F5');
}
return Ans::ret($ans, 'сервер доступен');
Exemplo n.º 3
0
<?php

use infrajs\access\Access;
use infrajs\config\Config;
use infrajs\ans\Ans;
use infrajs\mem\Mem;
use infrajs\path\Path;
use infrajs\router\Router;
if (!is_file('vendor/autoload.php')) {
    chdir('../../../');
    require_once 'vendor/autoload.php';
    Router::init();
}
Access::test(true);
Mem::flush();
Path::fullrmdir('!', true);
$ans = array();
Ans::ret($ans, 'Cache cleared Mem::flush, Path::fulrmdir');
Exemplo n.º 4
0
<?php

namespace infrajs\mem;

use infrajs\path\Path;
Path::mkdir(Mem::$conf['cache']);
$mem =& Mem::memcache();
if ($mem) {
    $mem->flush();
}
Exemplo n.º 5
0
 public static function cache($name, $fn, $args = array(), $re = false)
 {
     //Запускается один раз для админа, остальные разы возвращает кэш из памяти
     $name = 'Access::cache ' . $name;
     return Once::exec($name, function ($args, $name) use($name, $fn, $re) {
         $path = $name . '_' . Hash::make($args);
         $data = Mem::get($path);
         if (!$data) {
             $data = array('time' => 0);
         }
         $execute = self::adminIsTime($data['time'], function () {
             return true;
         }, $re);
         if ($execute) {
             $cache = !Nostore::check(function () use(&$data, $fn, $args, $re) {
                 $data['result'] = call_user_func_array($fn, array_merge($args, array($re)));
             });
             if ($cache) {
                 $data['time'] = time();
                 Mem::set($path, $data);
             } else {
                 Mem::delete($path);
             }
         }
         return $data['result'];
     }, array($args, $name), $re);
 }
Exemplo n.º 6
0
    if (!Load::isphp()) {
        header('Infrajs-Cache: false');
    }
    if ($isjs) {
        $code = Collect::js($name);
    } else {
        $code = Collect::css($name);
    }
    if ($isjs) {
        $min = new Minify\JS($code);
    } else {
        $min = new Minify\CSS($code);
    }
    if ($isgzip) {
        $code = $min->gzip();
    } else {
        $code = $min->minify();
    }
    Mem::set($key, $code);
}
if (!Load::isphp()) {
    if ($isgzip) {
        header('Content-Encoding: gzip');
        header('Vary: accept-encoding');
        header('Content-Length: ' . strlen($code));
    }
}
if ($isjs) {
    return Ans::js($code);
}
return Ans::css($code);
Exemplo n.º 7
0
Arquivo: Mem.php Projeto: infrajs/mem
            if ($dir) {
                if (!Path::$conf['fs']) {
                    throw new \Exception('Filesystem protected by Path::$conf[fs]=false set it on true');
                }
                foreach (glob($dir . '*.*') as $filename) {
                    @unlink($filename);
                }
            }
        }
    }
    public static function &memcache()
    {
        return Once::exec('Mem::memcache', function () {
            $conf = Mem::$conf;
            if ($conf['type'] != 'mem') {
                return false;
            }
            if (!class_exists('Memcache')) {
                return false;
            }
            if (!$conf['memcache']) {
                return false;
            }
            $infra_mem = new \Memcache();
            $infra_mem->connect($conf['memcache']['host'], $conf['memcache']['port']) or die('Could not connect');
            return $infra_mem;
        });
    }
}
Mem::$conf = array('type' => 'fs', 'memcache' => array('host' => 'localhost', 'port' => 23), 'cache' => Path::resolve('!mem/'));