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
28 changes: 14 additions & 14 deletions doc/cache-manager.md → doc/cache-invalidator.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The Cache Manager
The Cache Invalidator
=================

Use the CacheManager to explicitly invalidate or refresh paths, URLs or
Use the CacheInvalidator to explicitly invalidate or refresh paths, URLs or
headers.

* [Invalidating paths and URLs](#invalidating-paths-and-urls)
Expand All @@ -19,12 +19,12 @@ Make sure to configure your proxy for purging first.
Invalidate a path:

```php
$cacheManager->invalidatePath('/users');
$cacheInvalidator->invalidatePath('/users');
```

Invalidate an URL:
```php
$cacheManager->invalidatePath('http://www.example.com/users');
$cacheInvalidator->invalidatePath('http://www.example.com/users');
```

Refreshing paths and URLs
Expand All @@ -36,13 +36,13 @@ Make sure to configure your proxy for refreshing first.
Refresh a path:

```php
$cacheManager->refreshPath('/users');
$cacheInvalidator->refreshPath('/users');
```

Refresh an URL:

```php
$cacheManager->refreshPath('http://www.example.com/users');
$cacheInvalidator->refreshPath('http://www.example.com/users');
```

Invalidating with a Regular Expression
Expand All @@ -58,7 +58,7 @@ For instance, to invalidate all .png files for all host names handled by this
caching proxy:

```php
$cacheManager->invalidateRegex('.*png$');
$cacheInvalidator->invalidateRegex('.*png$');
```

If you need other criteria than the path, directly access the cache client.
Expand All @@ -67,10 +67,10 @@ See for example [Varnish](varnish.md#ban).
Fluent interface
----------------

The cache manager offers a fluent interface:
The cache invalidator offers a fluent interface:

```php
$cacheManager
$cacheInvalidator
->invalidatePath('/bad/guys')
->invalidatePath('/good/guys')
->refreshPath('/')
Expand All @@ -82,7 +82,7 @@ Tags

Make sure to [configure your proxy for tagging](varnish.md#tagging) first.
The examples in this section assume you left the `tagsHeader` unchanged. You
can call `CacheManager::setTagsHeader` to change the HTTP header used to
can call `CacheInvalidator::setTagsHeader` to change the HTTP header used to
identify tags.

You will have to make sure your web application adds the correct tags on all
Expand All @@ -100,7 +100,7 @@ Assume you sent 3 responses:
You can now invalidate some URLs using tags:

```php
$cacheManager->invalidateTags(array('group-a', 'tag-four'));
$cacheInvalidator->invalidateTags(array('group-a', 'tag-four'));
```

This will ban all requests having either the tag group-a OR tag-four. In the
Expand All @@ -110,18 +110,18 @@ will stay in the cache.
Flushing
--------

The CacheManager internally queues the invalidation requests and only sends
The CacheInvalidator internally queues the invalidation requests and only sends
them out to your HTTP proxy when you call `flush()`:

```php
$cacheManager
$cacheInvalidator
->invalidateRoute(...)
->invalidatePath(...)
->flush()
;
```

Note: When using the Symfony Bundle, the cache manager is automatically
Note: When using the Symfony Bundle, the cache invalidator is automatically
flushed. When using the Bundle, you only need to manually call flush when not
in a request context. (E.g. from a command.)

Expand Down
2 changes: 1 addition & 1 deletion doc/http-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Use the HTTP proxy classes (currently this library provides only a client for
Varnish) for lower-level access to invalidation functionality offered by your
HTTP proxy.

As with the CacheManager, you need to call `flush()` to actually send requests
As with the CacheInvalidator, you need to call `flush()` to actually send requests
to the backend.

* [Purge](#purge)
Expand Down
6 changes: 3 additions & 3 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ FOSHttpCache
============

This is the documentation for the FOSHttpCache library. This library provides
an architecture to do cache invalidation. It provides implementations to talk
to popular caching proxies.
a client to let applications do cache invalidation. It provides implementations
to talk to popular caching proxies.

If you are a Symfony user, have a look at the [FOSHttpCacheBundle](https://github.com/FriendsOfSymfony/FOSHttpCacheBundle)
which integrates this library and provides a lot off additional features.

This documentation covers:

1. [Installation and Getting Started](installation.md) of the library
2. [Cache Manager](cache-manager.md)
2. [Cache Invalidator](cache-invalidator.md)
1. [HTTP proxy](http-proxy.md), the low level details
3. HTTP proxy configuration
1. [Varnish](varnish.md)
Expand Down
12 changes: 6 additions & 6 deletions doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $ composer require friendsofsymfony/http-cache:@stable
Getting Started
===============

This library mainly provides the CacheManager class. Use this class to collect
This library mainly provides the CacheInvalidator class. Use this class to collect
cache invalidation requests in your application and call the `flush` method at
the end of requests to have it send the invalidation requests to your server.

Expand All @@ -29,7 +29,7 @@ Basically, there are 3 operations:
* Ban: This is a way more powerful operation. Remove all requests matching
specified regular expressions on any desired headers. This can invalidate a
subset of URLs but also custom headers, as used with the
CacheManager::invalidateTags method. In the case of Varnish, this will only
CacheInvalidator::invalidateTags method. In the case of Varnish, this will only
record the fact that cache entries are to be ignored, for performance
reasons.

Expand All @@ -39,13 +39,13 @@ All of these methods are explained in detail in the
Bootstrap
---------

The CacheManager is configured with an instance of CacheProxyInterface which
The CacheInvalidator is configured with an instance of CacheProxyInterface which
also implements at least one of PurgeInterface, RefreshInterface, BanInterface.
Using the provided Varnish client, the bootstrap code looks as follows:


```php
use FOS\HttpCache\CacheManager;
use FOS\HttpCache\CacheInvalidator;
use FOS\HttpCache\Invalidation\Varnish;

// IPs varnish is listening on
Expand All @@ -58,10 +58,10 @@ $varnish = new Varnish(array $ips, $host);
// logger instance
$varnish->setLogger(...);

$cacheManager = new CacheManager($varnish);
$cacheInvalidator = new CacheInvalidator($varnish);
```

Thats it, you are ready to start caching. Read on in the next chapter about the
[Cache Manager](cache-manager.md). You may also want to know more about the
[Cache Invalidator](cache-invalidator.md). You may also want to know more about the
[Lower-level HTTP proxy classes](http-proxy.md) like the `Varnish` class we
used in this example.
2 changes: 1 addition & 1 deletion doc/varnish.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ sub vcl_recv {
Tagging
-------

Add the following to your Varnish configuration to enable [cache tagging](cache-manager.md#tags).
Add the following to your Varnish configuration to enable [cache tagging](cache-invalidator.md#tags).

```varnish
sub vcl_recv {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @author David de Boer <david@driebit.nl>
*/
class CacheManager
class CacheInvalidator
{
/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace FOS\HttpCache\Tests;

use FOS\HttpCache\CacheManager;
use FOS\HttpCache\CacheInvalidator;
use FOS\HttpCache\Exception\UnsupportedInvalidationMethodException;
use \Mockery;

class CacheManagerTest extends \PHPUnit_Framework_TestCase
class CacheInvalidatorTest extends \PHPUnit_Framework_TestCase
{
protected $cacheManager;

public function setUp()
{
$this->cacheProxy = \Mockery::mock('\FOS\HttpCache\Invalidation\CacheProxyInterface');
Expand All @@ -22,9 +20,9 @@ public function testInvalidatePath()
->shouldReceive('flush')->once()
->getMock();

$cacheManager = new CacheManager($httpCache);
$cacheInvalidator = new CacheInvalidator($httpCache);

$cacheManager
$cacheInvalidator
->invalidatePath('/my/route')
->flush()
;
Expand All @@ -38,9 +36,9 @@ public function testRefreshPath()
->shouldReceive('flush')->never()
->getMock();

$cacheManager = new CacheManager($httpCache);
$cacheInvalidator = new CacheInvalidator($httpCache);

$cacheManager
$cacheInvalidator
->refreshPath('/my/route', $headers)
;
}
Expand All @@ -58,8 +56,8 @@ public function testInvalidateTags()
->once()
->getMock();

$cacheManager = new CacheManager($ban);
$cacheManager->invalidateTags(array('post-1', 'posts'));
$cacheInvalidator = new CacheInvalidator($ban);
$cacheInvalidator->invalidateTags(array('post-1', 'posts'));
}

public function testInvalidateTagsCustomHeader()
Expand All @@ -70,30 +68,30 @@ public function testInvalidateTagsCustomHeader()
->once()
->getMock();

$cacheManager = new CacheManager($ban);
$cacheManager->setTagsHeader('Custom-Tags');
$cacheManager->invalidateTags(array('post-1'));
$cacheInvalidator = new CacheInvalidator($ban);
$cacheInvalidator->setTagsHeader('Custom-Tags');
$cacheInvalidator->invalidateTags(array('post-1'));
}

public function testMethodException()
{
$proxy = \Mockery::mock('\FOS\HttpCache\Invalidation\CacheProxyInterface');
$cacheManager = new CacheManager($proxy);
$cacheInvalidator = new CacheInvalidator($proxy);
try {
$cacheManager->invalidatePath('/');
$cacheInvalidator->invalidatePath('/');
$this->fail('Expected exception');
} catch (UnsupportedInvalidationMethodException $e) {
// success
}
try {
$cacheManager->refreshPath('/');
$cacheInvalidator->refreshPath('/');
$this->fail('Expected exception');
} catch (UnsupportedInvalidationMethodException $e) {
// success
}
/*
try {
$cacheManager->invalidateRegex('/');
$cacheInvalidator->invalidateRegex('/');
$this->fail('Expected exception');
} catch (UnsupportedInvalidationMethodException $e) {
// success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

namespace FOS\HttpCache\Tests\Functional;

use FOS\HttpCache\CacheManager;
use FOS\HttpCache\CacheInvalidator;
use FOS\HttpCache\Tests\VarnishTestCase;

class CacheManagerTest extends VarnishTestCase
class CacheInvalidatorTest extends VarnishTestCase
{
public function testInvalidateTags()
{
$cacheManager = new CacheManager($this->varnish);
$cacheInvalidator = new CacheInvalidator($this->varnish);

$this->assertMiss(self::getResponse('/tags.php'));
$this->assertHit(self::getResponse('/tags.php'));

$cacheManager->invalidateTags(array('tag1'))->flush();
$cacheInvalidator->invalidateTags(array('tag1'))->flush();

$this->assertMiss(self::getResponse('/tags.php'));
}
Expand Down