@param string   $key
@param          $data
@param int|null $ttl
@param array    $tags

@return bool
@throws \Exception
@throws \TypeError
544096
public static function add(string $key, $data, ?int $ttl = null, array $tags = []) :bool
        {
            if ($tags) {
                foreach ($tags as $arrKey => $tagName) {
                    unset($tags[$arrKey]);

                    $tags[$tagName] = self::tagGetVer($tagName);
                }
            }

            $ttl    = $ttl === null ? self::$ttlDefault : ($ttl > self::$ttlMax ? self::$ttlMax : $ttl);
            $expire = $ttl ? time() + $ttl : 0;

            return self::GetInstance()->add("\$vxnKey:{$key}",
                                            [
                                                '$_data'   => $data,
                                                '$_tags'   => $tags,
                                                '$_ttl'    => $ttl,
                                                '$_expire' => $expire,
                                            ],
                                            null,
                                            $expire);
        }
1108623
public function set($key, array $tags, $data)
    {
        $key = $this->redis->prefix($key);
        $this->redis->set($key, $this->encoder->encode($data));

        if (is_int($this->expirationTime) && $this->expirationTime > 0) {
            $this->redis->expire($key, $this->expirationTime);
        }

        foreach ($tags as $tag) {
            $this->redis->sadd($this->redis->prefix($tag), $key);
        }
    }
1147284
protected function get(string $key, array $data = null)
    {
        /**
         * @var $loader mixed
         */
        $loader = $this->loader($key) ?: $data;

        if (null === $loader)
        {
            return true;
        }

        $mixed = [];

        if ($loader)
        {
            $mixed = $loader;

            if (\is_object($mixed))
            {
                $mixed = $loader->asArray();
            }
        }

        return $this->getLexemes($key, $mixed);
    }
1247335
private function hasValueAtKey($key, $data)
    {
        $keys = explode('.', $key);

        while (count($keys) > 0) {
            $key = array_shift($keys);

            // Wildcard Key
            if (preg_match($this->wildcards, $key) && is_array($data) && ! empty($data)) {
                // Shift the first item of the array
                if (preg_match('/^:(index|item)\[\d+\]$/', $key)) {
                    for ($x = substr($key, 7, -1); $x >= 0; $x--) {
                        if (empty($data)) {
                            return false;
                        }
                        $item = array_shift($data);
                    }
                } elseif ($key == ':last') {
                    $item = array_pop($data);
                } else {
                    $item = array_shift($data);
                }
                $data =& $item;
            } else {
                if ( ! isset($data[$key])) {
                    return false;
                }

                if (is_bool($data[$key])) {
                    return true;
                }

                if ($data[$key] === '') {
                    return false;
                }

                $data =& $data[$key];
            }
        }
        return true;
    }
1139722
public function write(string $key, $data, int $ttl = 0): bool
    {
        $ttl = ((int)$ttl <= 0) ? 0 : ((int)$ttl + time());
        $file = $this->cacheFile($key);
        $data = var_export(['ttl' => $ttl, 'data' => serialize($data)], true);
        $data = "<?php\n\rreturn " . preg_replace('/\s=>\s(\n\s+)array\s\(\n/', " => array (\n", $data) . ';';

        return $this->fileWrite($file, $data);
    }
585724
public function execute($key = null, $default = null, $data = null) {

		//Matching type array
		if(is_array($key)) {

			foreach($key as $index) {

				if(!isset($data[$index])) {
					return $default;
				}

				$data = $data[$index];
			}

			return $data;
		}

		//Matching type string
		if($key && isset($data[$key])) {
			return $data[$key];
		}

		//Matching type string array
		$names = explode('[', $key);

		foreach($names as $index => $name) {

			$name = rtrim($name, ']');

			if(!isset($data[$name])) {
				return null;
			}

			$data = $data[$name];

			if($index == count($names) - 1) {
				$default = $data;
			}
		}

		return $default;
	}
1035934
public function get($key, $default = null, $ttl = null)
    {
        try {
            return $this->_getCached($key, $default, $ttl);
        } catch (RootException $e) {
            if ($e instanceof ContainerExceptionInterface) {
                throw $e;
            }

            throw $this->_createContainerException($this->__('Could not set data'), null, $e, $this);
        }
    }
8909
public function tag_add($tag, $key)
    {
        if ($this->stopwatch) {
            $e = $this->getStopwatchEvent('tag_add');
        }

        $result = parent::tag_add($tag, $key);

        if ($this->stopwatch) {
            $e->stop();
        }

        return $result;
    }
224992
public function delete($key, $tags = '')
    {
        $cache = app('cache');

        if (!empty($tags)) {
            $tags = json_decode($tags, true);
            $cache = $cache->tags($tags);
        } else {
            unset($tags);
        }

        $success = $cache->forget($key);

        return response()->json(compact('success'));
    }
409965
public function getAndPut(string $key, $data, int $ttl = 0)
	{
		$storedValue = $this->get($key);

		$this->put($key, $data, $ttl);

		return $storedValue;
	}
620435
public function set($id, $data, $lifetime = null, $tags = null) {
		$backend = $this->getBackend();
		
		if ($tags !== null) {
			if (! $backend instanceof TaggableInterface) {
				throw new NoTagsSupported('Unable to set the data with the tag(s) due to a tags does not supported by the backend "' . get_class($backend) . '"');
			}
			
			if (is_array($tags)) {
				$tags = array_map([$this, 'prepareId'], $tags);
			} else {
				$tags = $this->prepareId($tags);
			}
		}
		
		$id = $this->prepareId($id);
		
		if ($lifetime === null) {
			$lifetime = $this->_defaultLifetime;
		}
		
		return $backend->set($id, $data, $lifetime, $tags);
	}
151797
protected function updatePreferencesForKey(string $key, Collection $tags)
	{
		$tags = str_replace('"', '', $tags->implode(','));

		$tags = Collection::make(explode(',', $tags))
			->merge(explode(',',$this->preferences[$key]))
			->unique()
			->take(self::MAX_TAGS)
			->implode(',');

		$this->preferences[$key] = rtrim($tags, ',');
	}
1368202
public function ttl($key, $db = -1)
    {
        if(-1 != $db) {
            $this->execute('select', array($db));
        }

        return $this->execute('ttl', array($key));
    }
1140583
public function requestByKey($key, $data, $onResponse = null)
    {
        $this->getConnectionByKey($key, function ($conn) use ($data, $onResponse) {
            if (!$conn->isConnected()) {
                return;
            }
            $conn->onResponse($onResponse);
            $conn->write($data);
        });
        return true;
    }
1362402
public function set($key, $data, $ttl = 3600)
    {
        if (empty($this->memcache)) {
            return false;
        }

        $key = $this->processKey($key);

        $compress = !empty($this->compress) ? MEMCACHE_COMPRESSED : 0;

        return $this->memcache->set($key, $data, $compress, $ttl);
    }
1084000
public function send($data, $sampleRate = 1, array $tags = null)
    {

        // sampling
        $sampledData = array();

        if ($sampleRate < 1) {
            foreach ($data as $stat => $value) {
                if ((mt_rand() / mt_getrandmax()) <= $sampleRate) {
                    $sampledData[] = [$stat, "$value|@$sampleRate"];
                }
            }
        } else {
            foreach ($data as $stat => $value) {
                $sampledData[] = [$stat, $value];
            }
        }

        if (empty($sampledData)) {
            return Observable::emptyObservable();
        }

        $observableSequence = Observable::fromArray($sampledData)
            ->map(function($d) use ($tags) {
                $stat = $d[0];
                $value = $d[1];
                if ($tags !== null && is_array($tags) && count($tags) > 0) {
                    $value .= '|';
                    foreach ($tags as $tag_key => $tag_val) {
                        if (is_array($tag_val)) {
                            $flattenTagVal = array();
                            array_walk_recursive($array, function($a) use (&$return) { $flattenTagVal[] = $a; });
                            $tag_val = implode("\n", $flattenTagVal);
                        }
                        $value .= '#' . $tag_key . ':' . $tag_val . ',';
                    }
                    $value = substr($value, 0, -1);
                }
                elseif (isset($tags) && !empty($tags)) {
                    $value .= '|#' . $tags;
                }
                return $this->reportMetric("$stat:$value");
            });
        return $observableSequence->mergeAll();
    }
13549
public function data( $key )
    {

        // string, key clause
        if( is_scalar( $key ) ) {

            $dataTypes = $this->dataTypesGet( DataType::PRIMARY_KEYS );
            try {
                $key = array_combine(
                    array_keys( $dataTypes ),
                    explode( Base::KEY_SEPARATOR, $key )
                );
            } catch ( \Exception $e ) {
                throw new BadKeyException(
                    sprintf(
                        "Passed key `%s` needs %d fragments; it has %d",
                        $key,
                        count( $dataTypes ),
                        count( explode( Base::KEY_SEPARATOR, $key ) )
                    )
                );
            }

        // is array
        } elseif( is_array( $key ) and count( $key ) > 0 ) {

            $dataTypes = $this->dataTypesGet( array_keys( $key ) );

        // bad argument
        } else {
            throw new \InvalidArgumentException("Can't lookup data for entity with this argument -> " . print_r( $key, true ) );
        }

        // we got the right amount of keyFragments?
        if( count($key) !== count($dataTypes) ) {
            throw new \InvalidArgumentException(
                sprintf(
                    "The passed key (%s) can't be married to the repository keys (%s). Epic fail.",
                    print_r($key, true),
                    implode(',', array_keys($dataTypes) )
                )
            );
        }

        // build where clause
        $where = array();
        foreach( $dataTypes as $name => $dataType ) {

            $where[] = sprintf(
                "%s = %s",
                $this->db->quoteIdent( $name ),
                $dataType->toQueryTag()
            );
            $data[$name] = $key[$name];

        }

        // build query
        $query = new Query(
            sprintf(
                "SELECT * FROM ONLY %s WHERE %s",
                $this->db->quoteIdent( $this->__get('table') ),
                implode( ' AND ', $where )
            ),
            $data
        );

        $result = $this->db->query( $query );
        $data = $result->fetch( Result::FETCH_SINGLE | Result::FLATTEN_PREVENT );

        return $data;

    }