Skip to content

Commit

Permalink
改进memcached驱动
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Dec 23, 2018
1 parent b56d75a commit 88a2ab6
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions library/think/cache/driver/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,67 @@ public function clear($tag = null)

return $this->handler->flush();
}

/**
* 缓存标签
* @access public
* @param string $name 标签名
* @param string|array $keys 缓存标识
* @param bool $overlay 是否覆盖
* @return $this
*/
public function tag($name, $keys = null, $overlay = false)
{
if (is_null($keys)) {
$this->tag = $name;
} else {
$tagName = $this->getTagKey($name);
if ($overlay) {
$this->handler->delete($tagName);
}

if (!$this->handler->has($tagName)) {
$this->handler->set($tagName, '');
}

foreach ($keys as $key) {
$this->handler->append($tagName, ',' . $key);
}
}

return $this;
}

/**
* 更新标签
* @access protected
* @param string $name 缓存标识
* @return void
*/
protected function setTagItem($name)
{
if ($this->tag) {
$tagName = $this->getTagKey($this->tag);

if ($this->handler->has($tagName)) {
$this->handler->append($tagName, ',' . $name);
} else {
$this->handler->set($tagName, $name);
}

$this->tag = null;
}
}

/**
* 获取标签包含的缓存标识
* @access public
* @param string $tag 缓存标签
* @return array
*/
public function getTagItem($tag)
{
$tagName = $this->getTagKey($tag);
return explode(',', trim($this->handler->get($tagName), ','));
}
}

0 comments on commit 88a2ab6

Please sign in to comment.