Skip to content

have flush return the count of successful invalidation requests #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2014
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
8 changes: 3 additions & 5 deletions src/CacheInvalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ public function invalidateTags(array $tags)
/**
* Send all pending invalidation requests.
*
* @throws ExceptionCollection
* @return int The number of cache invalidations performed per caching server.
*
* @return $this
* @throws ExceptionCollection If any errors occurred during flush.
*/
public function flush()
{
try {
$this->cache->flush();
return $this->cache->flush();
} catch (ExceptionCollection $exceptions) {
foreach ($exceptions as $exception) {
$event = new Event();
Expand All @@ -303,7 +303,5 @@ public function flush()

throw $exceptions;
}

return $this;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

noticed that what we really want is to get the number from the CacheInvalidator too, not just the proxy.

4 changes: 3 additions & 1 deletion src/Invalidation/AbstractCacheProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ public function flush()
{
$queue = $this->queue;
if (0 === count($queue)) {
return;
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that this is no real BC break as we did not respect the fluent interface we promised in the interface...

}

$this->queue = array();
$this->sendRequests($queue);

return count($queue);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Invalidation/CacheProxyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ interface CacheProxyInterface
/**
* Send all pending invalidation requests.
*
* @return $this
* @return int The number of cache invalidations performed per caching server.
*
* @throws ExceptionCollection If any errors occurred during flush
* @throws ExceptionCollection If any errors occurred during flush.
*/
public function flush();
}
6 changes: 3 additions & 3 deletions tests/Functional/Fixtures/varnish/purge.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ sub vcl_recv {
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged";
error 204 "Purged";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we send no body so its 204 not 200.

Copy link
Member

Choose a reason for hiding this comment

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

👍

}
}

sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 404 "Not in cache";
error 204 "Purged (Not in cache)";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

like this its still debuggable what is going on.

}
}
}
32 changes: 32 additions & 0 deletions tests/Unit/Invalidation/VarnishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,38 @@ public function testSetServersThrowsInvalidServerException()
new Varnish(array('http://127.0.0.1:80/some/weird/path'));
}

public function testFlushCountSuccess()
{
$self = $this;
$client = \Mockery::mock('\Guzzle\Http\Client[send]', array('', null))
->shouldReceive('send')
->once()
->with(
\Mockery::on(
function ($requests) use ($self) {
/** @type Request[] $requests */
$self->assertCount(4, $requests);
foreach ($requests as $request) {
$self->assertEquals('PURGE', $request->getMethod());
}

return true;
}
)
)
->getMock();

$varnish = new Varnish(array('127.0.0.1', '127.0.0.2'), 'fos.lo', $client);

$this->assertEquals(
2,
$varnish
->purge('/c')
->purge('/b')
->flush()
);
}

protected function setUp()
{
$this->mock = new MockPlugin();
Expand Down