php - Laravel: Use Memcache instead of Filesystem -


whenever load page, can see laravel reading great amount of data /storage folder.

generally speaking, dynamic reading , writing our filesystem bottleneck. using google app engine , our storage in google cloud storage, means 1 write or read equal "remote" api request. google cloud storage fast, feel it's slow, when laravel makes 10-20 cloud storage calls per request.

is possible store data in memcache instead of in /storage directory? believe give our systems lot better performance.

nb. both session , cache uses memcache, compiled views , meta stored on filesystem.

in order store compiled views in memcache you'd need replace storage blade compiler uses.

first of all, you'll need new storage class extends illuminate\filesystem\filesystem. methods bladecompiler uses listed below - you'll need make them use memcache.

  • exists
  • lastmodified
  • get
  • put

a draft of class below, might want make more sophisticated:

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 thing adding memcache config in config/view.php:

'memcached_host' => 'localhost', 'memcached_port' => 11211 

last thing you'll need overwrite blade.compiler service in 1 of service providers, uses brand new memcached storage:

$app->singleton('blade.compiler', function ($app) {     $cache = $app['config']['view.compiled'];      $storage = $app->make(memcachestorage::class);      return new bladecompiler($storage, $cache); }); 

that should trick.

please let me know if see typos or error, haven't had chance run it.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -