2011-07-20 12:57:07 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct script access.');
|
|
|
|
/**
|
|
|
|
* See [Kohana_Cache_Memcache]
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* @package Kohana/Cache
|
|
|
|
* @category Base
|
|
|
|
* @version 2.0
|
|
|
|
* @author Kohana Team
|
2013-04-13 06:17:56 +00:00
|
|
|
* @copyright (c) 2009-2012 Kohana Team
|
2011-07-20 12:57:07 +00:00
|
|
|
* @license http://kohanaphp.com/license
|
|
|
|
*/
|
2013-04-13 06:17:56 +00:00
|
|
|
class Kohana_Cache_MemcacheTag extends Cache_Memcache implements Cache_Tagging {
|
2011-07-20 12:57:07 +00:00
|
|
|
|
2013-04-13 06:17:56 +00:00
|
|
|
/**
|
2011-07-20 12:57:07 +00:00
|
|
|
* Constructs the memcache object
|
|
|
|
*
|
2013-04-13 06:17:56 +00:00
|
|
|
* @param array $config configuration
|
|
|
|
* @throws Cache_Exception
|
2011-07-20 12:57:07 +00:00
|
|
|
*/
|
|
|
|
protected function __construct(array $config)
|
|
|
|
{
|
|
|
|
parent::__construct($config);
|
|
|
|
|
|
|
|
if ( ! method_exists($this->_memcache, 'tag_add'))
|
|
|
|
{
|
2013-04-13 06:17:56 +00:00
|
|
|
throw new Cache_Exception('Memcached-tags PHP plugin not present. Please see http://code.google.com/p/memcached-tags/ for more information');
|
2011-07-20 12:57:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a value based on an id with tags
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
|
|
|
* @param string $id id
|
|
|
|
* @param mixed $data data
|
|
|
|
* @param integer $lifetime lifetime [Optional]
|
|
|
|
* @param array $tags tags [Optional]
|
2011-07-20 12:57:07 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function set_with_tags($id, $data, $lifetime = NULL, array $tags = NULL)
|
|
|
|
{
|
2013-04-13 06:17:56 +00:00
|
|
|
$id = $this->_sanitize_id($id);
|
|
|
|
|
2011-07-20 12:57:07 +00:00
|
|
|
$result = $this->set($id, $data, $lifetime);
|
|
|
|
|
|
|
|
if ($result and $tags)
|
|
|
|
{
|
|
|
|
foreach ($tags as $tag)
|
|
|
|
{
|
|
|
|
$this->_memcache->tag_add($tag, $id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete cache entries based on a tag
|
|
|
|
*
|
2013-04-13 06:17:56 +00:00
|
|
|
* @param string $tag tag
|
2011-07-20 12:57:07 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function delete_tag($tag)
|
|
|
|
{
|
|
|
|
return $this->_memcache->tag_delete($tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find cache entries based on a tag
|
|
|
|
*
|
2013-04-13 06:17:56 +00:00
|
|
|
* @param string $tag tag
|
2011-07-20 12:57:07 +00:00
|
|
|
* @return void
|
2013-04-13 06:17:56 +00:00
|
|
|
* @throws Cache_Exception
|
2011-07-20 12:57:07 +00:00
|
|
|
*/
|
|
|
|
public function find($tag)
|
|
|
|
{
|
2013-04-13 06:17:56 +00:00
|
|
|
throw new Cache_Exception('Memcached-tags does not support finding by tag');
|
|
|
|
}
|
2011-07-20 12:57:07 +00:00
|
|
|
}
|