Last active
November 11, 2017 13:00
-
-
Save wtnabe/06fb6a9e16fd90c123c70095be42790f to your computer and use it in GitHub Desktop.
Laravel Cache Initiator ( mainly for auth requiring Memcached server )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://laravel-recipes.com/recipes/94/setting-up-the-memcached-cache-driver この辺にある設定の並びにそのまま username, password が書かれている(もちろん環境変数などから動的に)のを前提に。サーバが増えたら頑張れ。