Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Last active November 11, 2017 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtnabe/06fb6a9e16fd90c123c70095be42790f to your computer and use it in GitHub Desktop.
Save wtnabe/06fb6a9e16fd90c123c70095be42790f to your computer and use it in GitHub Desktop.
Laravel Cache Initiator ( mainly for auth requiring Memcached server )
<?php
class CacheInitiator
{
static function run()
{
$initializer = "init".ucfirst(strtolower(Cache::getDefaultDriver()));
$self = new CacheInitiator();
if ( method_exists($self, $initializer) ) {
$self->{$initializer}();
}
}
function initMemcached()
{
$memcached = Cache::getStore()->getMemcached();
$memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$username = Config::get('cache.memcached')[0]['username'];
$password = Config::get('cache.memcached')[0]['password'];
if ( $username && $password ) {
$memcached->setSaslAuthData($username, $password);
}
}
}
CacheInitiator::run();
@wtnabe
Copy link
Author

wtnabe commented Nov 11, 2017

http://laravel-recipes.com/recipes/94/setting-up-the-memcached-cache-driver この辺にある設定の並びにそのまま username, password が書かれている(もちろん環境変数などから動的に)のを前提に。サーバが増えたら頑張れ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment