1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php namespace Laravel;
- class Memcached {
-
- protected static $connection;
-
- public static function connection()
- {
- if (is_null(static::$connection))
- {
- static::$connection = static::connect(Config::get('cache.memcached'));
- }
- return static::$connection;
- }
-
- protected static function connect($servers)
- {
- $memcache = new \Memcached;
- foreach ($servers as $server)
- {
- $memcache->addServer($server['host'], $server['port'], $server['weight']);
- }
- if ($memcache->getVersion() === false)
- {
- throw new \Exception('Could not establish memcached connection.');
- }
- return $memcache;
- }
-
- public static function __callStatic($method, $parameters)
- {
- return call_user_func_array(array(static::instance(), $method), $parameters);
- }
- }
|