<?php
namespace Illuminate\Cache;
use Illuminate\Contracts\Cache\Store;
// a namespace about Store;
class TaggedCache extends Repository
{// TaggedCache a son about the Repository,
use RetrievesMultipleKeys;// use a way to many too
/**
* The tag set instance.
* The tag set instance.
* @var \Illuminate\Cache\TagSet
*/
protected $tags;// a tag to set the instance
/**
* Create a new tagged cache instance.
*
* @param \Illuminate\Contracts\Cache\Store $store
* @param \Illuminate\Cache\TagSet $tags
* @return void
*/
public function __construct(Store $store, TagSet $tags)
{
parent::__construct($store);
$this->tags = $tags;
}// Create a new tagged cache instance.
// use parent::__construct($store)
// create a tag by tags.
/**
* {@inheritdoc}
*/
protected function fireCacheEvent($event, $payload)
{// fire Cache Event
$payload[] = $this->tags->getNames();// get the tag payLoad area
parent::fireCacheEvent($event, $payload);
}// use parent function fire Cache Event
/**
* Increment the value of an item in the cache.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function increment($key, $value = 1)
{
$this->store->increment($this->itemKey($key), $value);
}// Increment the value of an item in the cache.
// increment a key, like value++
/**
* Increment the value of an item in the cache.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function decrement($key, $value = 1)
{
$this->store->decrement($this->itemKey($key), $value);
}// decrement the value about key
/**
* Remove all items from the cache.
*
* @return void
*/
public function flush()
{
$this->tags->reset();
}// Remove all items from the cache.
/**
* {@inheritdoc}
*/
protected function itemKey($key)
{
return $this->taggedItemKey($key);
}// get item Key
/**
* Get a fully qualified key for a tagged item.
*
* @param string $key
* @return string
*/
public function taggedItemKey($key)
{
return sha1($this->tags->getNamespace()).':'.$key;
}// get a fully qualified key for a tagged item.
}
转载于:https://blog.51cto.com/jingshanls/1759952