public function testHash() { $a = []; $this->assertTrue('40cd750bba9870f18aada2478b24840a' === Hash::make($a)); $a[] = 'Передали текст'; $this->assertTrue('c6a45e965497496002680ac385b17b05' === Hash::make($a)); $a[] = function () { }; $this->assertTrue('c6008bd78fcdc1a923c65ecddc8f67ba' === Hash::make($a)); $a[] = new Hash(); $this->assertTrue('58843b5ad3da812f794515abe816c979' === Hash::make($a)); $b = new Hash(); $this->assertTrue('639cb6369416f4178c26b9fabba9a38f' === Hash::make($b)); $b = true; $this->assertTrue('431014e4a761ea216e9a35f20aaec61c' === Hash::make($b)); $b = false; $this->assertTrue('a2072c8a50f1127f73a55a6b5f574da7' === Hash::make($b)); $b = 15; $this->assertTrue('3ae4e7e87b9038a299ee40119700914a' === Hash::make($b)); $b = 'текст'; $this->assertTrue('c899e3abc57a1426a4404a74e0a5a0cf' === Hash::make($b)); $b = function () { }; $this->assertTrue('b35bcc328f12fccc6d8c7f7ed98cd0f1' === Hash::make($b)); }
public static function clear($name, $args = array()) { if (empty(self::$store[$name])) { return; } if ($args === true) { unset(self::$store[$name]); return; } if (sizeof($args)) { $hash = Hash::make($args); } else { $hash = ''; } unset(self::$store[$name][$hash]); return; }
return Ans::err('Noimage Not found'); } } if ($getorig) { Access::admin(true); } if (!is_null($ignoremark)) { Access::admin(true); } if ($getorig) { Access::admin(true); } $gray = isset($_GET['gray']); $args = array($src, $ignoremark, $mark, $default, $getorig, $w, $h, $crop, $top, $gray); $execute = false; $cachesrc = Imager::$conf['cache'] . 'resize/' . Hash::make($args); if (is_file($cachesrc)) { $cachetime = filemtime($cachesrc); } else { $cachetime = 0; } $time = filemtime(Path::theme($isrc)); if ($re || $time > $cachetime) { $execute = true; } if (!$execute) { $ans = Load::loadJSON($cachesrc); $ans['data'] = Load::loadTEXT($cachesrc . '.data'); if (!$ans['data']) { $execute = true; }
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); }