Normalize the cache key.

@param mixed       $item
@param string|null $key
5856
protected function normalizeKey($item, $key = null)
    {
        // If the user wants to provide their own cache
        // key, we'll opt for that.
        if (is_string($item) || is_string($key)) {
            return is_string($item) ? $item : $key;
        }
        
        // Otherwise we'll try to use the item to calculate
        // the cache key, itself.
        if (is_object($item) && method_exists($item, 'getCacheKey')) {
            return $item->getCacheKey();
        }
    
        // If we're dealing with a collection, we'll 
        // use a hashed version of its contents.
        if ($item instanceof \Illuminate\Support\Collection) {
            return md5($item);
        }
    
        throw new Exception('Could not determine an appropriate cache key.');
    }
758540
public function delete($key)
    {
        if (! $this->has($key)) return null;

        $value = $this->items[$key];

        unset($this->items[$key]);

        return $value;
    }
615056
protected function internalSetItem(&$normalizedKey, &$value)
    {
        /** @var Cache $cache  */
        $cache = Core::make($this->cacheName);
        $item = $cache->getItem('zend/'.$normalizedKey);

        if ($result = $item->set($value, $this->cacheLifetime)) {
            $item->save();
        }

        return $result;
    }
458299
public function useKeyAsIndexAttribute($key, $normalize = false)
    {
        if (null === $key) {
            $this->indexAttrKey = null;
            return;
        }

        if (true !== $normalize && !$this->isValidNodeName($key)) {
            throw new \InvalidArgumentException(sprintf('%s is an invalid attribute name', $key));
        }

        $this->indexAttrKey = $normalize ? $this->normalizer->normalize($key) : $key;
    }
1090652
protected static function setCache($id = null, $item = null)
    {
        static::getCacheInstance()->set(static::getCacheId($id), $item);

        return $item;
    }
794223
public function getItemUrl($item)
    {
        $item = $this->getItem($item);
        return $item ? $item->normalizedUrl : null;
    }
224193
public function forget($key = null)
    {
        $key = str_replace('.', '/user-', $key);

        return Arr::set($this->items, $key, ':to-be-deleted:');
    }
709041
public function chain($item=null) {
    list($item) = self::_wrapArgs(func_get_args(), 1);
    
    $__ = (isset($this) && isset($this->_chained) && $this->_chained) ? $this : __($item);
    $__->_chained = true;
    return $__;
  }
340608
public function set($key, $value)
    {
        $key = $this->normalizeKey($key);

        if (null === $key) {
            $this->data[] = $value;
        } else {
            $this->data[$key] = $value;
        }

        return $this;
    }
518904
private function normalizeArray(array &$data)
    {
        $normalizedData = array();

        foreach ($data as $key => $val) {
            $normalizedKey = $this->normalizeString($key);

            if ($normalizedKey !== $key) {
                if (array_key_exists($normalizedKey, $normalizedData)) {
                    throw new NormalizationException(sprintf(
                        'The key "%s" is invalid as it will override the existing key "%s"',
                        $key,
                        $normalizedKey
                    ));
                }
            }

            $normalizedData[$normalizedKey] = $val;
            $key = $normalizedKey;

            if (is_array($val)) {
                $this->normalizeArray($normalizedData[$key]);
            }
        }

        $data = $normalizedData;
    }
758035
public function get($key)
    {
        if (! $this->has($key)) {
            return null;
        }
        
        return $this->items[$this->normalizeKey($key)];
    }
661518
public function setItem(Item $item = null)
    {
        if ($this->item !== $item) {
            // romove link on this item for old item
            if ($this->item instanceof Item) {
                $tmp = $this->item;
                $this->item = null;
                $tmp->removeImage($this);
            }
            $this->item = $item;
            // add link on this item
            if ($item instanceof Item) {
                $this->item->addImage($this);
            }
        }

        return $this;
    }
204618
public function normalizeStateOrCityData($item)
    {
        $fields = [
            ['cca2', 'iso_a2'],
            ['name.common', 'admin'],
            ['name.official', 'admin'],
            ['adm0_a3', 'adm0_a3'],
        ];

        list(, $countryCode) = $this->findByFields($this->_countries, $item, $fields, 'cca3');

        if (is_null($countryCode)) {
            $countryCode = $this->helper->caseForKey($item['name']);
        }

        $item['iso_a3'] = ! isset($item['iso_a3'])
            ? $countryCode
            : $item['iso_a3'];

        $item['cca3'] = $item['iso_a3'];

        $item['cca2'] = $item['iso_a2'];

        return $item;
    }
1095492
public function set($key, $value)
	{
		$key = $this->normalizeKey($key);

		$this->items[$key] = $this->normalizeValue($value);

		return $this->items[$key];
	}
771154
public function set($key, $value)
    {
        if (!is_array($value)) {
            $value = [$value];
        }
        parent::set($this->normalizeKey($key), [
            'value' => $value,
            'originalKey' => $key
        ]);
    }
1286264
public function min($key)
	{
		return $this->reduce(function($result, $item) use ($key)
		{
			return is_null($result) || $item->{$key} < $result ? $item->{$key} : $result;
		});
	}
295198
public function set($key, $value)
    {
        if (! is_scalar($key)) {
            throw InvalidArgumentException('Invalid key type');
        }
        $this->items[$this->normalizeKey($key)] = $value;
    }