コード例 #1
0
ファイル: Cache.php プロジェクト: infrajs/cache
 public static function exec($conds, $name, $fn, $args = array(), $re = false)
 {
     $name = 'Cache::exec' . $name;
     return Once::exec($name, function ($args, $r, $hash) use($name, $fn, $conds, $re) {
         $data = Mem::get($name . $hash);
         if (!$data) {
             $data = array('time' => 0);
         }
         $execute = Access::adminIsTime($data['time'], function ($cache_time) use($conds) {
             if (!sizeof($conds)) {
                 return false;
                 //Если нет conds кэш навсегда и develop не поможет
             }
             $max_time = 1;
             for ($i = 0, $l = sizeof($conds); $i < $l; $i++) {
                 $mark = $conds[$i];
                 $mark = Path::theme($mark);
                 if (!$mark) {
                     continue;
                 }
                 $m = filemtime($mark);
                 if ($m > $max_time) {
                     $max_time = $m;
                 }
                 if (!is_dir($mark)) {
                     continue;
                 }
                 foreach (glob($mark . '*.*') as $filename) {
                     $m = filemtime($filename);
                     if ($m > $max_time) {
                         $max_time = $m;
                     }
                 }
             }
             return $max_time > $cache_time;
         }, $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($name . $hash, $data);
             } else {
                 Mem::delete($name . $hash);
             }
         }
         return $data['result'];
     }, array($args), $re);
 }
コード例 #2
0
ファイル: Access.php プロジェクト: infrajs/access
 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);
 }
コード例 #3
0
ファイル: mem-cache.php プロジェクト: infrajs/mem
<?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, 'сервер доступен');
コード例 #4
0
ファイル: index.php プロジェクト: infrajs/collect
    $key = 'Infrajs::Collect::' . $isjs . true;
    //Кэш с zip
    Mem::delete($key);
    $key = 'Infrajs::Collect::' . $isjs . false;
    //Кэш без zip
    Mem::delete($key);
    if ($isjs) {
        return Ans::js($code);
    }
    return Ans::css($code);
}
$p = explode(',', str_replace(' ', '', $_SERVER['HTTP_ACCEPT_ENCODING']));
$isgzip = !Load::isphp() && in_array('gzip', $p);
$key = 'Infrajs::Collect::' . $isjs . $isgzip;
//Два кэша зазипованый и нет. Не все браузеры понимают зазипованую версию.
$code = Mem::get($key);
if (!$code) {
    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) {