<commit_before><?php

namespace FOS\HttpCacheBundle;

use FOS\HttpCacheBundle\HttpCache\HttpCacheInterface;
use FOS\HttpCacheBundle\Invalidation\CacheProxyInterface;
use FOS\HttpCacheBundle\Invalidation\Method\BanInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;

/**
 * Manages HTTP cache invalidations
 *
 */
class CacheManager
{
    /**
     * @var string
     */
    protected $tagsHeader = 'X-Cache-Tags';

    /**
     * @var HttpCacheInterface
     */
    protected $cache;

    /**
     * @var RouterInterface
     */
    protected $router;

    /**
     * Invalidation queue
     *
     * @var array
     */
    protected $invalidationQueue = array();

    /**
     * Constructor
     *
     * @param CacheProxyInterface $cache  HTTP cache
     * @param RouterInterface     $router Symfony router
     */
    public function __construct(CacheProxyInterface $cache, RouterInterface $router)
    {
        $this->cache = $cache;
        $this->router = $router;
    }

    /**
     * Set the HTTP header name that will hold cache tags
     *
     * @param string $tagsHeader
     */
    public function setTagsHeader($tagsHeader)
    {
        $this->tagsHeader = $tagsHeader;
    }

    /**
     * Get the HTTP header name that will hold cache tags
     *
     * @return string
     */
    public function getTagsHeader()
    {
        return $this->tagsHeader;
    }

    /**
     * Assign cache tags to a response
     *
     * @param Response $response
     * @param array    $tags
     * @param bool     $replace  Whether to replace the current tags on the
     *                           response
     *
     * @return $this
     */
    public function tagResponse(Response $response, array $tags, $replace = false)
    {
        if (!$replace) {
            $tags = array_merge(
                $response->headers->get($this->getTagsHeader(), array()),
                $tags
            );
        }

        $uniqueTags = array_unique($tags);
        $response->headers->set($this->getTagsHeader(), implode(',', $uniqueTags));

        return $this;
    }

    /**
     * Invalidate a path (URL)
     *
     * @param string $path Path
     *
     * @return $this
     */
    public function invalidatePath($path, array $headers = array())
    {
        $this->invalidationQueue[$path] = $headers;

        return $this;
    }

    /**
     * Invalidate a route
     *
     * @param string $name       Route name
     * @param array  $parameters Route parameters (optional)
     *
     * @return $this
     */
    public function invalidateRoute($name, $parameters = array())
    {
        $this->invalidatePath($this->router->generate($name, $parameters));

        return $this;
    }

    public function refreshPath($path, $headers)
    {
        $headers = array("Cache-Control: no-cache, no-store, max-age=0, must-revalidate");

    }



    public function invalidateRegex($regex)
    {

    }

    /**
     * Invalidate cache tags
     *
     * @param array $tags Cache tags
     *
     * @return $this
     * @throws \RuntimeException If HTTP cache does not support BAN requests
     */
    public function invalidateTags(array $tags)
    {
        if (!$this->cache instanceof BanInterface) {
            throw new \RuntimeException('HTTP cache does not support BAN requests');
        }

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

        return $this;
    }

    /**
     * Send all invalidation requests
     *
     */
    public function flush()
    {
        $this->cache->flush();
    }

    /**
     * Get paths (URLs) that are queued for invalidation
     *
     * @return array
     */
    public function getInvalidationQueue()
    {
        return \array_values($this->invalidationQueue);
    }
}<commit_msg>Add refresh methods to cache manager<commit_after><?php

namespace FOS\HttpCacheBundle;

use FOS\HttpCacheBundle\Invalidation\CacheProxyInterface;
use FOS\HttpCacheBundle\Invalidation\Method\BanInterface;
use FOS\HttpCacheBundle\Invalidation\Method\PurgeInterface;
use FOS\HttpCacheBundle\Invalidation\Method\RefreshInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;

/**
 * Manages HTTP cache invalidations
 *
 */
class CacheManager
{
    /**
     * @var string
     */
    protected $tagsHeader = 'X-Cache-Tags';

    /**
     * @var CacheProxyInterface
     */
    protected $cache;

    /**
     * @var RouterInterface
     */
    protected $router;

    /**
     * Constructor
     *
     * @param CacheProxyInterface $cache  HTTP cache
     * @param RouterInterface     $router Symfony router
     */
    public function __construct(CacheProxyInterface $cache, RouterInterface $router)
    {
        $this->cache = $cache;
        $this->router = $router;
    }

    /**
     * Set the HTTP header name that will hold cache tags
     *
     * @param string $tagsHeader
     */
    public function setTagsHeader($tagsHeader)
    {
        $this->tagsHeader = $tagsHeader;
    }

    /**
     * Get the HTTP header name that will hold cache tags
     *
     * @return string
     */
    public function getTagsHeader()
    {
        return $this->tagsHeader;
    }

    /**
     * Assign cache tags to a response
     *
     * @param Response $response
     * @param array    $tags
     * @param bool     $replace  Whether to replace the current tags on the
     *                           response
     *
     * @return $this
     */
    public function tagResponse(Response $response, array $tags, $replace = false)
    {
        if (!$replace) {
            $tags = array_merge(
                $response->headers->get($this->getTagsHeader(), array()),
                $tags
            );
        }

        $uniqueTags = array_unique($tags);
        $response->headers->set($this->getTagsHeader(), implode(',', $uniqueTags));

        return $this;
    }

    /**
     * Invalidate a path or URL
     *
     * @param string $path Path or URL
     *
     * @return $this
     * @throws \RuntimeException
     */
    public function invalidatePath($path)
    {
        if (!$this->cache instanceof PurgeInterface) {
            throw new \RuntimeException('HTTP cache does not support PURGE requests');
        }

        return $this->cache->purge($path);

        return $this;
    }

    /**
     * Invalidate a route
     *
     * @param string $name       Route name
     * @param array  $parameters Route parameters (optional)
     *
     * @return $this
     */
    public function invalidateRoute($name, $parameters = array())
    {
        $this->invalidatePath($this->router->generate($name, $parameters));

        return $this;
    }

    /**
     * Refresh a path or URL
     *
     * @param string $path   Path or URL
     * @param array $headers HTTP headers (optional)
     *
     * @return $this
     * @throws \RuntimeException
     */
    public function refreshPath($path, array $headers = array())
    {
        if (!$this->cache instanceof RefreshInterface) {
            throw new \RuntimeException('HTTP cache does not support refresh requests');
        }

        $this->cache->refresh($path, $headers);

        return $this;
    }

    /**
     * Refresh a route
     *
     * @param string $route     Route name
     * @param array $parameters Route parameters (optional)
     *
     * @return $this
     */
    public function refreshRoute($route, array $parameters = array())
    {
        $this->refreshPath($this->router->generate($route, $parameters));

        return $this;
    }



    public function invalidateRegex($regex)
    {

    }

    /**
     * Invalidate cache tags
     *
     * @param array $tags Cache tags
     *
     * @return $this
     * @throws \RuntimeException If HTTP cache does not support BAN requests
     */
    public function invalidateTags(array $tags)
    {
        if (!$this->cache instanceof BanInterface) {
            throw new \RuntimeException('HTTP cache does not support BAN requests');
        }

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

        return $this;
    }

    /**
     * Send all invalidation requests
     *
     */
    public function flush()
    {
        $this->cache->flush();
    }
}
{'fraction_non_alphanumeric': 0.1206281227694504, 'fraction_numerical': 0.00011896264572924102, 'mean_word_length': 2.0671287851149214, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3463296', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2324, 'n_words': 596}