Skip to content

Symfony HttpCache listener for custom ttl header #214

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
Aug 2, 2015
Merged

Conversation

dbu
Copy link
Contributor

@dbu dbu commented Jun 16, 2015

fix #151

i guess its ok if this only goes to version 2, its not urgent but for completeness.

TODO

  • Document
  • Functional test

i opt for including this here rather than the bundle, for consistency of where we have http cache listeners. we could also move the vcl and documentation for the varnish custom ttl here - that would also make it easy to test that vcl as we already have the whole setup here.

@ddeboer
Copy link
Member

ddeboer commented Jun 16, 2015

👍

Agreed on having it in the library: everything which is not strictly (full-stack) Symfony should go here.

@dbu
Copy link
Contributor Author

dbu commented Jun 17, 2015

cool. can you please review the implementation - would prefer to fix implementation before writing documentation and more tests ;-)
@dantleech @chirimoya can you please also have a look? i chose a different approach than you did in sulu, but would hope that once this is tagged stable you can switch to this over your implementation. if there are good reasons to prefer your implementation, please tell them - we can still change things here.

{
private $ttlHeader;

const SMAXAGE_BACKUP = 'FOS-Smaxage-Backup';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also be configurable? Not important I guess.

Copy link
Contributor Author

@dbu dbu Jun 18, 2015 via email

Choose a reason for hiding this comment

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

@chirimoya
Copy link

+1


const SMAXAGE_BACKUP = 'FOS-Smaxage-Backup';

public function __construct($ttlHeader = 'X-Reverse-Proxy-TTL')
Copy link
Member

Choose a reason for hiding this comment

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

Please add docblock explaining the $ttlHeader param.

@ddeboer
Copy link
Member

ddeboer commented Jun 20, 2015

Let’s pull this into 2.0. So needs a rebase. 😉

@ddeboer
Copy link
Member

ddeboer commented Jul 4, 2015

Please add docs and a test.

@dbu
Copy link
Contributor Author

dbu commented Jul 25, 2015

ok, added documentation and a test. also some random cleanup in the doc. notably i started to write the calls to our subs into the corresponding doc section, rather than the extremly flaky includes.

@@ -109,10 +111,22 @@ Constant Getter Default
``VARNISH_PORT`` ``getCachingProxyPort()`` ``6181`` port Varnish listens on
``VARNISH_MGMT_PORT`` ``getVarnishMgmtPort()`` ``6182`` Varnish management port
``VARNISH_CACHE_DIR`` ``getCacheDir()`` ``sys_get_temp_dir()`` + ``/foshttpcache-varnish`` directory to use for cache
``VARNISH_VERSION`` ``getVarnishVersion()`` ``4`` installed varnish application version
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was rather puzzling me with my varnish 3 locally. i think it does make sense to use an environment over a constant here.

Copy link
Member

Choose a reason for hiding this comment

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

Should we then remove the constant and getter for VARNISH_VERSION? I prefer to keep them, as it’s consistent this way with the other config params. I agree that you’ll typically set the Varnish version through an env var. By the way, testing against multiple Varnish versions is most useful for library/framework code; and less relevant for users testing an app against their caching setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i am not removing anything except wrong documentation. i added documentation for the environment variable and keep the getter that is using the env variable. we use the env variable both in VarnishTestCase and tests/bootstrap.php

we could alternatively look at both or have tests/bootstrap.php copy the env variable into a constant. but that all feels a bit clumsy and just as confusing.

issue invalidation requests. Let’s call the ACL `invalidators`. The ACL below
will be used throughout the Varnish examples on this page.
To invalidate cached objects in Varnish, begin by adding an `ACL` (for Varnish
3 see `ACL for Varnish 3`_) to your Varnish configuration. This ACL determines
Copy link
Member

Choose a reason for hiding this comment

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

We should have a Varnish 3 tab below with the ACL config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is no difference actually. i just wanted to link to the proper version of the documentation. not sure how we should handle that. duplicating the doc config with no difference seems a bit strange. should i just say that this did not change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this question is still open. @ddeboer want me to do anything more here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, updated. its actually no longer just an example...

@dbu
Copy link
Contributor Author

dbu commented Jul 27, 2015

updated

const struct gethdr_s hdr = { HDR_BERESP, "\024X-Reverse-Proxy-TTL:" };
ttl = VRT_GetHdr(ctx, &hdr);
VRT_l_beresp_ttl(ctx, atoi(ttl));
}C
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ddeboer do you see what is wrong here? i have the include above, and the code as you did in the playground. but tests are still not happy. any ideas? can i not include from an included file?

Copy link
Member

Choose a reason for hiding this comment

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

You’re missing char *ttl; before line 30 where ttl is used: error: ‘ttl’ undeclared (first use in this function).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh well. seems i got confused by reading the diff and then just not thinking. thanks!

@dbu
Copy link
Contributor Author

dbu commented Aug 1, 2015

if this is green, i want to squash before we merge.

final review anybody?

@ddeboer
Copy link
Member

ddeboer commented Aug 1, 2015

Looks good to me. Go ahead and squash. 😄

@dbu
Copy link
Contributor Author

dbu commented Aug 2, 2015

squashed and some last cleanup. please check and merge if you are happy.

ddeboer added a commit that referenced this pull request Aug 2, 2015
Symfony HttpCache listener for custom ttl header
@ddeboer ddeboer merged commit 843ead4 into master Aug 2, 2015
@ddeboer ddeboer deleted the custom-ttl branch August 2, 2015 11:14
@ddeboer
Copy link
Member

ddeboer commented Aug 2, 2015

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symfony HttpCache subscriber for custom proxy ttl
4 participants