1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
3 * Memcache-based Cache driver.
5 * $Id: Memcache.php 3917 2009-01-21 03:06:22Z zombor $
9 * @copyright (c) 2007-2008 Kohana Team
10 * @license http://kohanaphp.com/license.html
12 class Cache_Memcache_Driver
implements Cache_Driver
{
14 // Cache backend object and flags
18 public function __construct()
20 if ( ! extension_loaded('memcache'))
21 throw new Kohana_Exception('cache.extension_not_loaded', 'memcache');
23 $this->backend
= new Memcache
;
24 $this->flags
= Kohana
::config('cache_memcache.compression') ? MEMCACHE_COMPRESSED
: 0;
26 $servers = Kohana
::config('cache_memcache.servers');
28 foreach ($servers as $server)
30 // Make sure all required keys are set
31 $server +
= array('host' => '127.0.0.1', 'port' => 11211, 'persistent' => FALSE);
33 // Add the server to the pool
34 $this->backend
->addServer($server['host'], $server['port'], (bool) $server['persistent'])
35 or Kohana
::log('error', 'Cache: Connection failed: '.$server['host']);
39 public function find($tag)
44 public function get($id)
46 return (($return = $this->backend
->get($id)) === FALSE) ?
NULL : $return;
49 public function set($id, $data, $tags, $lifetime)
51 count($tags) and Kohana
::log('error', 'Cache: Tags are unsupported by the memcache driver');
53 // Memcache driver expects unix timestamp
59 return $this->backend
->set($id, $data, $this->flags
, $lifetime);
62 public function delete($id, $tag = FALSE)
65 return $this->backend
->flush();
68 return $this->backend
->delete($id);
73 public function delete_expired()
78 } // End Cache Memcache Driver