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
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Changelog

See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpCache/releases).

2.15.4
------

* Fix always use defined `CustomTtlListener` header even if not set.
* Fix not calling store if Response object is not longer cachable after event listeners.

2.15.3
------

Expand Down
9 changes: 5 additions & 4 deletions src/SymfonyCache/CustomTtlListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ public function __construct($ttlHeader = 'X-Reverse-Proxy-TTL', $keepTtlHeader =
public function useCustomTtl(CacheEvent $e)
{
$response = $e->getResponse();
if (!$response->headers->has($this->ttlHeader)) {
return;
}
dbu marked this conversation as resolved.
Show resolved Hide resolved
$backup = $response->headers->hasCacheControlDirective('s-maxage')
? $response->headers->getCacheControlDirective('s-maxage')
: 'false'
;
$response->headers->set(static::SMAXAGE_BACKUP, $backup);
$response->setTtl($response->headers->get($this->ttlHeader));
$response->setTtl(
$response->headers->has($this->ttlHeader)
? $response->headers->get($this->ttlHeader)
: 0
);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/SymfonyCache/EventDispatchingHttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ protected function store(Request $request, Response $response)
{
$response = $this->dispatch(Events::PRE_STORE, $request, $response);

parent::store($request, $response);
// CustomTtlListener or other Listener or Subscribers might have set a non-cacheable response so we need revalidate this
alexander-schranz marked this conversation as resolved.
Show resolved Hide resolved
// So store is only called when cacheable like Symfony core would do: https://github.com/symfony/symfony/blob/v7.1.2/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php#L409
alexander-schranz marked this conversation as resolved.
Show resolved Hide resolved
if ($response->isCacheable()) {
parent::store($request, $response);
}
alexander-schranz marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Loading