Skip to content
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

Add fallbackToSmaxage flag to CustomTtlListener and check for isCacheable before calling store #575

Closed

Conversation

alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented Jul 22, 2024

We have the CustomTtlListener enabled but we have controllers which set only a s-maxage the s-maxage is in our case always only for browsers and should never used by Symfony or Varnished HttpCache / reverse proxy.

The current CustomTtlListener still fallbacks always back to s-maxage / maxage this should in my opinion not the case if CustomTtlListener the HttpCache should only listen on the configured header and ignore the max age headers.

/cc @Toflar @dbu Alternativily we should also add a option to the CustomTtlListener disableFallback / enableFallback.

Update

As discussed below we will add additional fallbackToSmaxage = true parameter to make it possible to disable that fallback mechanism.

Additional this pull request adds a recheck for $response->isCachable after the listeners were run. That not only improve performance for response setting a ttl to 0 but its now possible to set a response to private in a preHandle listener event to also disable the caching.

@alexander-schranz alexander-schranz marked this pull request as draft July 22, 2024 14:24
@alexander-schranz alexander-schranz marked this pull request as ready for review July 22, 2024 14:54
@dbu dbu changed the title Never us shared max age if CustomTtlListener is enabled Never use shared max age if CustomTtlListener is enabled Jul 23, 2024
Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thanks. we can do the extra flag - though setting custom ttl to 0 should have the same effect.

can you explain the flag in the documentation as well, please?
https://github.com/FriendsOfSymfony/FOSHttpCache/blob/3.x/doc/symfony-cache-configuration.rst#custom-ttl

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
src/SymfonyCache/CustomTtlListener.php Outdated Show resolved Hide resolved
src/SymfonyCache/CustomTtlListener.php Outdated Show resolved Hide resolved
src/SymfonyCache/CustomTtlListener.php Outdated Show resolved Hide resolved
src/SymfonyCache/CustomTtlListener.php Outdated Show resolved Hide resolved
src/SymfonyCache/EventDispatchingHttpCache.php Outdated Show resolved Hide resolved
src/SymfonyCache/EventDispatchingHttpCache.php Outdated Show resolved Hide resolved
src/SymfonyCache/CustomTtlListener.php Outdated Show resolved Hide resolved
tests/Unit/SymfonyCache/CustomTtlListenerTest.php Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@alexander-schranz alexander-schranz changed the title Never use shared max age if CustomTtlListener is enabled Add fallbackToSmaxage flag to CustomTtlListener and check for isCacheable before calling store Jul 23, 2024
Co-authored-by: David Buchmann <[email protected]>
dbu pushed a commit that referenced this pull request Jul 23, 2024
* Only call store when response still is cacheable
* Add flag to disable fallback to s-maxage to changelog
@dbu
Copy link
Contributor

dbu commented Jul 23, 2024

squashed and merged as 6957dee

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.

2 participants