-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpCache] purge both http and https from http cache #21582
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,14 +317,30 @@ private function getMetadata($key) | |
/** | ||
* Purges data for the given URL. | ||
* | ||
* This method purges both the HTTP and the HTTPS version of the cache entry. | ||
* | ||
* @param string $url A URL | ||
* | ||
* @return bool true if the URL exists and has been purged, false otherwise | ||
* @return bool true if the URL exists with either HTTP or HTTPS scheme and has been purged, false otherwise | ||
*/ | ||
public function purge($url) | ||
{ | ||
$key = $this->getCacheKey(Request::create($url)); | ||
$http = preg_replace('#^https#', 'http', $url); | ||
$https = preg_replace('#^http#', 'https', $url); | ||
|
||
return $this->doPurge($http) || $this->doPurge($https); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the title of this PR, I would have expected this to be an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my thinking was that when either http or https was purged we report that something was purged. the chances that both http and https were in cache are small. i think the most sane use case for this is when doing cache invalidation, e.g. with FOSHttpCache: you need to send a request to the specific host by ip, rather than the domain name, to target each server instance. but if you do that over https, you get certificate mismatches and thus want to use http. apart from such special cases, your webserver should probably redirect requests from http to https rather than allow both. |
||
} | ||
|
||
/** | ||
* Purges data for the given URL. | ||
* | ||
* @param string $url A URL | ||
* | ||
* @return bool true if the URL exists and has been purged, false otherwise | ||
*/ | ||
private function doPurge($url) | ||
{ | ||
$key = $this->getCacheKey(Request::create($url)); | ||
if (isset($this->locks[$key])) { | ||
flock($this->locks[$key], LOCK_UN); | ||
fclose($this->locks[$key]); | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
if $url is already http://, nothing changes.
this was previously
but i find the new code more readable. we add one preg_replace instead of a strpos. given that we do multiple filesystem operations, the speed difference should not matter.