Beispiel #1
0
 /**
  * Constructor
  *
  * @param CacheInvalidator $invalidator The invalidator instance.
  * @param string           $tagsHeader  Header to use for tags, defaults to X-Cache-Tags.
  *
  * @throws UnsupportedProxyOperationException If CacheInvalidator does not support invalidate requests
  */
 public function __construct(CacheInvalidator $invalidator, $tagsHeader = 'X-Cache-Tags')
 {
     if (!$invalidator->supports(CacheInvalidator::INVALIDATE)) {
         throw UnsupportedProxyOperationException::cacheDoesNotImplement('BAN');
     }
     $this->invalidator = $invalidator;
     $this->tagsHeader = $tagsHeader;
 }
 /**
  * Invalidate URLs based on a regular expression for the URI, an optional
  * content type and optional limit to certain hosts.
  *
  * The hosts parameter can either be a regular expression, e.g.
  * '^(www\.)?(this|that)\.com$' or an array of exact host names, e.g.
  * ['example.com', 'other.net']. If the parameter is empty, all hosts
  * are matched.
  *
  * @see BanInterface::banPath()
  *
  * @param string       $path        Regular expression pattern for URI to
  *                                  invalidate.
  * @param string       $contentType Regular expression pattern for the content
  *                                  type to limit banning, for instance 'text'.
  * @param array|string $hosts       Regular expression of a host name or list of
  *                                  exact host names to limit banning.
  *
  * @throws UnsupportedProxyOperationException If HTTP cache does not support BAN requests
  *
  * @return $this
  */
 public function invalidateRegex($path, $contentType = null, $hosts = null)
 {
     if (!$this->cache instanceof BanInterface) {
         throw UnsupportedProxyOperationException::cacheDoesNotImplement('BAN');
     }
     $this->cache->banPath($path, $contentType, $hosts);
     return $this;
 }
 /**
  * Invalidate cache entries that contain any of the specified tags in their
  * tag header.
  *
  * @param array $tags Cache tags
  *
  * @throws UnsupportedProxyOperationException If HTTP cache does not support BAN requests
  *
  * @return $this
  *
  * @deprecated Use TagHandler::invalidateTags instead.
  */
 public function invalidateTags(array $tags)
 {
     if (!$this->tagHandler) {
         throw UnsupportedProxyOperationException::cacheDoesNotImplement('BAN');
     }
     $this->tagHandler->invalidateTags($tags);
     return $this;
 }
Beispiel #4
0
    /**
     * Invalidate cache entries that contain any of the specified tags in their
     * tag header.
     *
     * @see BanInterface::ban()
     *
     * @param array $tags Cache tags
     *
     * @throws UnsupportedProxyOperationException If HTTP cache does not support BAN requests
     *
     * @return $this
     */
    public function invalidateTags(array $tags)
    {
        if (!$this->cache instanceof BanInterface) {
            throw UnsupportedProxyOperationException::cacheDoesNotImplement('BAN');
        }

        $headers = array($this->getTagsHeader() => '('.implode('|', array_map('preg_quote', $tags)).')(,.+)?$');
        $this->cache->ban($headers);

        return $this;
    }