Skip to content
This repository was archived by the owner on Sep 3, 2026. It is now read-only.

HTTP cache multi-tagging purge client - #1894

Closed
bdunogier wants to merge 4 commits into
feature-http_cache_multi_taggingfrom
http_cache_purge_client
Closed

bdunogier wants to merge 4 commits into
feature-http_cache_multi_taggingfrom
http_cache_purge_client

Conversation

@bdunogier

@bdunogier bdunogier commented Jan 24, 2017 •

Copy link
Copy Markdown
Contributor

Part of EZP-22401

Adds support for new multi-tagging capabilities to cache purge clients:

  • FOSPurgeClient will iterate over the given cache tags, and send one purge request for each
  • LocalPurgeClient will send a unique request, with the tags separated by |, since the symfony Proxy knows how to handle that.

Changes since the previous feature branch

  • Updated fos_http_cache.md
  • Tried to prevent the BC break on PurgeClientInterface

TODO

@bdunogier
bdunogier changed the base branch from master to feature-http_cache_multi_tagging January 24, 2017 21:46
@bdunogier
bdunogier force-pushed the http_cache_purge_client branch from c879770 to 20ea6e7 Compare January 24, 2017 21:47
@bdunogier bdunogier changed the title HTTP cache multi-tagging purge client WIP: HTTP cache multi-tagging purge client Jan 24, 2017
@bdunogier

bdunogier commented Jan 24, 2017 •

Copy link
Copy Markdown
Contributor Author

@andrerom can you have a look, mostly at the fos_http_cache.md file ? The PurgeClientInterface changes aren't final yet.

Varnish proxy client from FOSHttpCache lib is now used for clearing eZ Http cache, even when using Symfony HttpCache.
A single `BAN` request is sent to registered purge servers, containing a `X-Location-Id` header.
This header contains all Location IDs for which objects in cache need to be cleared.
A single `BAN` request is sent to registered purge servers, containing a `xkey` header.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not BAN, its typically a PURGE when we deal with xkey

A single `BAN` request is sent to registered purge servers, containing a `X-Location-Id` header.
This header contains all Location IDs for which objects in cache need to be cleared.
A single `BAN` request is sent to registered purge servers, containing a `xkey` header.
This header contains cache items tags that need to be cleared.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

item, xkey (side: and fastly) currently only supports clearing one tag per request, so several requests are made.

*
* @param array $locationIds Cache resource(s) to purge (e.g. array of URI to purge in a reverse proxy)
*/
public function purge($locationIds);

@andrerom andrerom Jan 25, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't think we need to add purge and purgeAll here, its still on the old interface also being implemented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Clearly a mistake, it wasn't supposed to end up here.


$purgeRequest = Request::create('http://localhost/', 'BAN');
$purgeRequest->headers->set('X-Location-Id', '(' . implode('|', $locationIds) . ')');
$purgeRequest = Request::create('http://localhost/', 'PURGE');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As far as I can tell, this won't work if the server is configured to use HTTPS.


if (!is_array($locationIds)) {
$locationIds = array($locationIds);
// As xkey only support one tag (key) being invalidated at a time, we loop.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To align with xkey offical example as is also done in FOS and our VCL PR, lets change this to use key (only for Purges, for response headers for tags we use xkey as automatically used by the VMOD).


$this->cacheManager->invalidatePath(
'/',
['xkey' => $tag, 'Host' => empty($_SERVER['SERVER_NAME']) ? 'localhost' : $_SERVER['SERVER_NAME']]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

key

public function purgeAll()
{
$this->cacheManager->invalidate(array('X-Location-Id' => '.*'));
$this->cacheManager->invalidate(['xkey' => '.*']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

key

$purgeRequest = Request::create('http://localhost/', 'BAN');
$purgeRequest->headers->set('X-Location-Id', '(' . implode('|', $locationIds) . ')');
$purgeRequest = Request::create('http://localhost/', 'PURGE');
$purgeRequest->headers->set('xkey', implode(' ', $tags));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

key

Varnish proxy client from FOSHttpCache lib is now used for clearing eZ Http cache, even when using Symfony HttpCache.
A single `BAN` request is sent to registered purge servers, containing a `X-Location-Id` header.
This header contains all Location IDs for which objects in cache need to be cleared.
It sends, for each cache tag that needs to be expired, a `PURGE` request with a `xkey` header to the registered purge servers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

key

@bdunogier
bdunogier force-pushed the http_cache_purge_client branch from 9f45ec0 to 8388e6b Compare January 30, 2017 16:30
@bdunogier
bdunogier force-pushed the http_cache_purge_client branch from dc22773 to f00af38 Compare January 30, 2017 23:52
@bdunogier

bdunogier commented Jan 30, 2017 •

Copy link
Copy Markdown
Contributor Author

This should be good to merge. Could you update your review if it's good to go for you as well @andrerom ?

@bdunogier bdunogier changed the title WIP: HTTP cache multi-tagging purge client HTTP cache multi-tagging purge client Jan 30, 2017
@bdunogier
bdunogier force-pushed the http_cache_purge_client branch from f00af38 to bfc5b64 Compare January 31, 2017 11:02

@andrerom andrerom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, but what is the failure about?

@bdunogier

Copy link
Copy Markdown
Contributor Author
1) eZ\Publish\Core\FieldType\Tests\DateAndTimeTest::testFromHash with data set #3 (array('now'), eZ\Publish\Core\FieldType\DateAndTime\Value Object (...))
fromHash() method did not create expected result.
Failed asserting that 1485860774 is less than 1485860774.

Hum...

@andrerom

Copy link
Copy Markdown
Contributor

ok that would most likely be buggy test.

@bdunogier

Copy link
Copy Markdown
Contributor Author

Yeah, it seems so. It passes locally on all branches. Restarted it.

@bdunogier

Copy link
Copy Markdown
Contributor Author

Replaced by http://github.com/ezsystems/ezplatform-http-cache. Please do not delete the branch yet.

@bdunogier bdunogier closed this Feb 8, 2017
@alongosz
alongosz deleted the http_cache_purge_client branch July 2, 2019 13:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants