Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ public function tagResponse(Response $response, array $tags, $replace = false)
*
* @param string $name Route name
* @param array $parameters Route parameters (optional)
* @param array $headers Extra HTTP headers to send to the caching proxy (optional)
*
* @return $this
*/
public function invalidateRoute($name, array $parameters = array())
public function invalidateRoute($name, array $parameters = array(), array $headers = array())
{
$this->invalidatePath($this->urlGenerator->generate($name, $parameters));
$this->invalidatePath($this->urlGenerator->generate($name, $parameters), $headers);

return $this;
}
Expand All @@ -89,12 +90,13 @@ public function invalidateRoute($name, array $parameters = array())
*
* @param string $route Route name
* @param array $parameters Route parameters (optional)
* @param array $headers Extra HTTP headers to send to the caching proxy (optional)
*
* @return $this
*/
public function refreshRoute($route, array $parameters = array())
public function refreshRoute($route, array $parameters = array(), array $headers = array())
{
$this->refreshPath($this->urlGenerator->generate($route, $parameters));
$this->refreshPath($this->urlGenerator->generate($route, $parameters), $headers);

return $this;
}
Expand Down
13 changes: 12 additions & 1 deletion Resources/doc/features/invalidation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Cache Manager
-------------

To invalidate single paths, URLs and routes manually, use the
``invalidatePath($path)`` and ``invalidateRoute($route, $params)`` methods on
``invalidatePath($path, $headers)`` and ``invalidateRoute($route, $params, $headers)`` methods on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you did not implement this yet, its on the FOSHttpCache library, not the bundle...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR now submitted to FOSHttpCache bundle

the cache manager::

$cacheManager = $container->get('fos_http_cache.cache_manager');
Expand All @@ -32,6 +32,10 @@ the cache manager::
// Invalidate a route
$cacheManager->invalidateRoute('user_details', array('id' => 123))->flush();

// Invalidate a route or path with headers
$cacheManager->invalidatePath('/users', array('X-Foo' => 'bar'))->flush();
$cacheManager->invalidateRoute('user_details', array('id' => 123), array('X-Foo' => 'bar'))->flush();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should do a similar note here as ddboer did in the other PR, linking to http://foshttpcachebundle.readthedocs.org/en/latest/reference/configuration/proxy-client.html#custom-guzzle-client

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

To invalidate multiple representations matching a regular expression, call
``invalidateRegex($path, $contentType, $hosts)``::

Expand All @@ -41,6 +45,13 @@ To refresh paths and routes, you can use ``refreshPath($path)`` and
``refreshRoute($route, $params)`` in a similar manner. See
:doc:`/reference/cache-manager` for more information.


By default, the proxy clients instantiate a `Guzzle client`_ to communicate
with the caching proxy. If you need to customize the requests, for example to
send a basic authentication header, you can inject a custom Guzzle client::
See the
:doc:`/reference/configuration/proxy-client#custom-guzzle-client` configuration reference.

.. _invalidation configuration:

Configuration
Expand Down
8 changes: 6 additions & 2 deletions Tests/Unit/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public function setUp()
public function testInvalidateRoute()
{
$httpCache = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface')
->shouldReceive('purge')->once()->with('/my/route')
->shouldReceive('purge')->once()->with('/route/with/params/id/123')
->shouldReceive('purge')->once()->with('/my/route', array())
->shouldReceive('purge')->once()->with('/route/with/params/id/123', array())
->shouldReceive('purge')->once()->with('/route/with/params/id/123', array('X-Foo' => 'bar'))
->shouldReceive('flush')->once()
->getMock();

Expand All @@ -46,6 +47,7 @@ public function testInvalidateRoute()

$cacheManager->invalidateRoute('my_route')
->invalidateRoute('route_with_params', array('id' => 123))
->invalidateRoute('route_with_params', array('id' => 123), array('X-Foo' => 'bar'))
->flush();
}

Expand All @@ -54,6 +56,7 @@ public function testRefreshRoute()
$httpCache = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface')
->shouldReceive('refresh')->once()->with('/my/route', null)
->shouldReceive('refresh')->once()->with('/route/with/params/id/123', null)
->shouldReceive('refresh')->once()->with('/route/with/params/id/123', array('X-Foo' => 'bar'))
->shouldReceive('flush')->never()
->getMock();

Expand All @@ -72,6 +75,7 @@ public function testRefreshRoute()
$cacheManager
->refreshRoute('my_route')
->refreshRoute('route_with_params', array('id' => 123))
->refreshRoute('route_with_params', array('id' => 123), array('X-Foo' => 'bar'))
;
}

Expand Down