class sfTagedCache
{
protected $cache = null;
public function __construct($way)
{
$this->cache = MyUtils::getCache2($way);
}
public function hasTag($tag)
{
return $this->cache->has('tag.'.$tag);
}
public function setTags($tags)
{
foreach($tags as $tag)
$this->cache->set('tag.'.$tag, null);
}
public function removeTags($tags = array())
{
foreach($tags as $tag)
$this->cache->remove('tag.'.$tag);
}
public function get($key, $tags = array())
{
$taged = true;
foreach($tags as $tag)
if (!$this->hasTag($tag))
$taged = false;
if ($this->cache->has($key) && $taged)
return unserialize($this->cache->get($key));
else
return null;
}
public function set($key, $tags = array(), $data)
{
$this->cache->set($key, serialize($data));
$this->setTags($tags);
}
}