To save compiled views to Memcache , you need to replace the repository that uses the Blade Compiler .
First of all, you need a new storage class that extends Illuminate \ Filesystem \ Filesystem . Listed below are the methods used by BladeCompiler : you will need to use Memcache.
- exist
- Lastmodified
- receive
- to place
The project of this class is below, you can make it more complex:
class MemcacheStorage extends Illuminate\Filesystem\Filesystem {
protected $memcached;
public function __construct() {
$this->memcached = new Memcached();
$this->memcached->addServer(Config::get('view.memcached_host'), Config::get('view.memcached_port');
}
public function exists($key) {
return !empty($this->get($key));
}
public function get($key) {
$value = $this->memcached->get($key);
return $value ? $value['content'] : null;
}
public function put($key, $value) {
return $this->memcached->set($key, ['content' => $value, 'modified' => time()]);
}
public function lastModified($key) {
$value = $this->memcached->get($key);
return $value ? $value['modified'] : null;
}
}
Second, add memcache configuration to config / view.php :
'memcached_host' => 'localhost',
'memcached_port' => 11211
, , blade.compiler , memcached:
$app->singleton('blade.compiler', function ($app) {
$cache = $app['config']['view.compiled'];
$storage = $app->make(MemcacheStorage::class);
return new BladeCompiler($storage, $cache);
});
.
, , , .