-
Notifications
You must be signed in to change notification settings - Fork 61
Symfony taggable cache #376
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
Conversation
Are you sure I should not extract an extra library? Maybe we should wait for Javier's response there? |
238a548
to
2ae81c0
Compare
@Toflar okay, pushed my last changes. mainly i realized that the cache directory parameter only makes sense when not passing the cache and lock instance to the store, so i moved it into the options as well. i also refactored the OptionsResolver to use closures for the default cache and lock implementation to avoid instantiating them when not needed. this looks ready to me. do you want to take the store and its test into its own repo and create a readme from the doc section on the store? |
Perfect, thank you! Yes, I'll take care extracting it into its own library and then I'll update my original PR against FOSHttpCache and see if I can build some kind of bridge. Would that be fine with you? |
great! i did some tweaks in this branch. can you do the update from this branch? or i can just edit it myself, its mostly deleting the things that moved to your repo anyways :-) i would keep the store with the tag handling support - its basically free with PSR-6. then there should be no need to bridge things, we can just tell in the doc to require your repo when you want cache tagging in symfony HttpCache, and everything should just work the same as it works now in this pull request (apart from adjusting the namespace of the store) |
Yeah I'll let you know when it's ready :) |
Here we go: https://github.com/Toflar/psr6-symfony-http-cache-store 😄 Registered over at packagist already too, so you could update the PR requiring |
df19852
to
0290e22
Compare
thank you! i update the PR, but tests fail because the Psr6Store is final. this feels stupid, seems to be something with how we do the mocking of the store in the unit test. lets gather some feedback on the store and then release it asap. to merge this, i'd want at least an 1.0.0-alpha1 - i think thats reasonable to do soon. |
) { | ||
$store = new Psr6Store([ | ||
'cache_directory' => $kernel->getCacheDir(), | ||
'cache_tags_header' => 'X-Cache-Tags', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You noticed. Well done!
Yeah I think it should not be extended but I can remove it. I just don't want to provide BC for child classes... |
having it final seems correct to me. but how to test? i wonder if it could make sense to define an interface for this that extends the symfony StoreInterface with the prune and invalidateTags methods. that would define clearly what is added, and we could mock the interface... |
0290e22
to
5eadc48
Compare
Makes sense to me, I also mocked the |
that looks great! i added some comments about wording and naming, but the structure is exactly what i had in mind. |
34c2763
to
07eedae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. I added symfony/lock and /cache to the dependencies for now - the @dev
is not inherited from bundles, so we can't install this with default stability.
that means we will have to wait until symfony 3.4 is released, then release your library and then i can update here and we can merge and release...
composer.json
Outdated
@@ -36,7 +36,8 @@ | |||
"php-http/mock-client": "^0.3.2", | |||
"symfony/process": "^2.3||^3.0", | |||
"symfony/http-kernel": "^2.3||^3.0", | |||
"phpunit/phpunit": "^5.7 || ^6.0" | |||
"phpunit/phpunit": "^5.7 || ^6.0", | |||
"toflar/psr6-symfony-http-cache-store": "dev-master" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should create an alpha release before merging this
composer.json
Outdated
"phpunit/phpunit": "^5.7 || ^6.0", | ||
"toflar/psr6-symfony-http-cache-store": "dev-master", | ||
"symfony/lock": "^3.4@dev", | ||
"symfony/cache": "^3.4@dev" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to adjust this once the psr6-symfony-http-cache-store and symfony 3.4 are released.
CHANGELOG.md
Outdated
* [Testing] Upgraded phpunit to 5.7 / 6. If you use anything from the | ||
`FOS\HttpCache\Test` namespace you need to update your project to use | ||
PHPUnit 6 (or 5.7, if you are using PHP 5.6). | ||
* [Symfony HttpCache] Added a `TaggableStore` for tag based invalidation with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i deleted the wrong half of this :-( thanks for spotting, fixed
doc/symfony-cache-configuration.rst
Outdated
|
||
To support :doc:`cache tags <response-tagging>`, register the | ||
``PurgeTagsListener``. The purge listener needs the special | ||
``Toflar\Psr6HttpCacheStore\Psr6Store`` cache store with tag support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tagging support
doc/symfony-cache-configuration.rst
Outdated
information on the store. | ||
|
||
To install the store, run | ||
``composer require toflar/psr6-symfony-http-cache-store dev-master``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove dev-master
here. Once we release it it's obsolete and composer will choose the right version anyway :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. i thought we might merge this before the store is tagged, but as we have to wait for stable symfony 3.4 anyways we can wait.
07eedae
to
9664698
Compare
src/ProxyClient/Symfony.php
Outdated
$resolver->setDefault('purge_tags_header', PurgeTagsListener::DEFAULT_PURGE_TAGS_HEADER); | ||
$resolver->setAllowedTypes('purge_tags_header', 'string'); | ||
$resolver->setDefault('purge_tags_header_length', 7500); | ||
$resolver->setAllowedTypes('purge_tags_header_length', 'int'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should perhaps align config naming with Varnish one or the other way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also code wise easier to read if setDefaults()
is used imo: https://github.com/FriendsOfSymfony/FOSHttpCache/pull/332/files#diff-006816ea733cc0564d6a5b345ed47929R160
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed with setDefaults. for the naming i agree as long as its really the same semantics. we can't change existing names easily, because backwards compatibility is important.
with 3.4 now in beta2 I guess this can be updated to Is there plans for functional tests here? |
i want to wait with merging until 3.4 is tagged as stable release. functional tests would indeed be good. i don't have the time to build them - if toflar finds the time to do them would be awesome! |
b564705
to
cd0a2c1
Compare
5bd72d6
to
9fc1319
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i rebased on master, hopefully the build is now green.
@Toflar would you have time to address the unifcation of varnish vs symfony proxy client method to invalidate tags avoiding too long http headers?
src/ProxyClient/HttpProxyClient.php
Outdated
* | ||
* @return array | ||
*/ | ||
protected function splitLongHeaderValue($value, $length = 7500, $delimiter = ',') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finally looking over this again and i notice that this method is quite different from what we do to solve the same problem in Varnish::invalidateTags. can we instead put the logic from Varnish::invalidateTags into a HttpProxyClient::generateTagInvalidationChunks and use that for both?
this method is inefficient because the caller first implodes all tags, then splits them again and builds chunks from it
hm, the toflar store requires symfony kernel 3.0 or newer. is it time to drop symfony 2 support here? or would it be easy to allow symfony 2 in the store? |
I don't think they can be unified. The Varnish proxy requires a very special regex-style invalidation header which makes absolutely no sense for the SF proxy.
It depends on the |
Not sure but we wanted to add it as a |
but technically lock can be installed independently right? same as with cache afaik |
@dbu Maybe we can try to do that as followup once/if xkey gets in? |
the question was about the store and this is based on top of both of these components so they are a requirement 😊 but the whole store lib is optional for foscache 😊 |
composer.json
Outdated
"symfony/process": "^2.3 || ^3.0 || ^4.0", | ||
"symfony/http-kernel": "^2.3 || ^3.0 || ^4.0", | ||
"phpunit/phpunit": "^5.7 || ^6.0" | ||
"symfony/lock": "^3.4 || ^4.0", | ||
"symfony/cache": "^3.4 || ^4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Toflar do we need the lock and cache as direct dependency? guess not, we only had that for stability weakening? the store brings them and its the store that has the dependency, not directly us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're not needed. They're dev
requirements anyway and I guess it's a leftover from the times where the store implementation was part of this PR and not a separate lib yet :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was also probably needed during dev/beta of lock :)
1ff4612
to
4d1627b
Compare
@Toflar i refactored the tag invalidation header splitting. can you check if you have any feedback? i think i am now happy with this. |
Nice work, I've added a comment about the delimiter but otherwise: 👍 |
src/ProxyClient/HttpProxyClient.php
Outdated
{ | ||
if (mb_strlen($value) <= $length) { | ||
return [$value]; | ||
if (mb_strlen(implode(',', $escapedTags)) < $this->options['header_length']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either I'm blind or my comment is gone? Hope I do not repeat myself here now but just in case: I mentioned that ,
is hardcoded now but I might want to use foobar
as a delimiter which later affects the length of the header so it should be the second argument of this method :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you commented on the commit, instead of in the pull request ;-)
thanks for the input, i guess i should indeed pass in the delimiter, it costs us nothing and is future proof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both xkey and Surrogate-Key (Fastly) works with space separated tags afaik, so a bit outside of this but might be worth to either abstract as stated in this thread or even just align.
ef5e897
to
1705566
Compare
@andrerom i added whitespace to the things to replace in tags. do you want to refactor this PR to use spaces instead of comma? i don't have time to do it and want to merge it this week... |
I'm unsure if I have time for my own PR's, so would not bet on that, we are doing two releases in parallel for end of year, one is major. |
sounds like a busy week indeed. i think its not that important that we are consistent with the separator between different caches, as each cache has its own client anyways. i will revert the whitespace escaping for now. thanks to the failing tests i realized that this would be a potential BC break if you don't wipe the cache after deploying this version - invalidations would then use the new escaping and not hit old tags. |
3fe903b
to
427cb38
Compare
@Toflar want to do a last review of this before i merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks all just fine to me, will try to integrate it as soon as possible so in case I'd stumble over anything we may still release a quick hotfix but I don't expect this to happen :)
4e602a4
to
b1ce46c
Compare
yay, done! thanks a ton! i will only tag the library next week, hopefully getting the other big contribution with varnish xkey support in. if you spot something until monday, we can just get it into the head. otherwise we can still to a .1 patch release with a fix. its a new feature, so no drama if that happens. |
Thanks everyone! |
replace #373, fix #286
squashed all commits and did some tweaks to the documentation.
TODO
@beta
in composer.json=> Bundle support: FriendsOfSymfony/FOSHttpCacheBundle#403