[ create a new paste ] login | about

Link: http://codepad.org/G2ucGkt4    [ raw code | fork ]

PHP, pasted on Dec 28:
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);
  }
}


Create a new paste based on this one


Comments: