memcacheD, если он не стоит то тогда memcache
<?php
class Cache
{
private $memcache;
public function __construct()
{
if (extension_loaded('memcache'))
{
$this->memcache = new Memcache();
$this->memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
}
}
public function __destruct()
{
$this->memcache->close();
}
public function save($key, $data, $time = 0)
{
$this->memcache->set($key, $data, MEMCACHE_COMPRESSED, $time);
}
public function load($key)
{
$get_result = $this->memcache->get($key);
return $get_result;
}
public function delete($key)
{
$this->memcache->delete($key);
}
public function clear()
{
$this->memcache->flush();
}
public static function make(Closure $object, $time, $key){
$cache = new Cache();
if (!$cacheData = $cache->load($key)){
$object = is_callable($object) ? call_user_func($object):$object;
$cache->save($key, $object, $time);
return $object;
}
else
{
return $cacheData;
}
}
}
// Cache::make($value, $time, $key);
$data = Cache::make(function(){
return DB::from("users")->orderBy("name DESC")->paginate(28)->fetchAll();
}, 5, md5($_SERVER['REQUEST_URI']) );