-
Notifications
You must be signed in to change notification settings - Fork 61
addTags on TagHandler #171
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.versionmodified { | ||
font-weight: bold; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,11 @@ class TagHandler | |
*/ | ||
private $tagsHeader; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $tags = array(); | ||
|
||
/** | ||
* Constructor | ||
* | ||
|
@@ -49,6 +54,40 @@ public function __construct(CacheInvalidator $invalidator, $tagsHeader = 'X-Cach | |
$this->tagsHeader = $tagsHeader; | ||
} | ||
|
||
/** | ||
* Get the HTTP header name that will hold cache tags. | ||
* | ||
* @return string | ||
*/ | ||
public function getTagsHeaderName() | ||
{ | ||
return $this->tagsHeader; | ||
} | ||
|
||
/** | ||
* Get the value for the HTTP tag header. | ||
* | ||
* This concatenates all tags and ensures correct encoding. | ||
* | ||
* @return string | ||
*/ | ||
public function getTagsHeaderValue() | ||
{ | ||
return implode(',', array_unique($this->escapeTags($this->tags))); | ||
} | ||
|
||
/** | ||
* Add tags to be sent. | ||
* | ||
* This must be called before any response is sent to the client. | ||
* | ||
* @param array $tags List of tags to add. | ||
*/ | ||
public function addTags(array $tags) | ||
{ | ||
$this->tags = array_merge($this->tags, $tags); | ||
} | ||
|
||
/** | ||
* Invalidate cache entries that contain any of the specified tags in their | ||
* tag header. | ||
|
@@ -59,10 +98,26 @@ public function __construct(CacheInvalidator $invalidator, $tagsHeader = 'X-Cach | |
*/ | ||
public function invalidateTags(array $tags) | ||
{ | ||
$tagExpression = sprintf('(%s)(,.+)?$', implode('|', array_map('preg_quote', $tags))); | ||
$tagExpression = sprintf('(%s)(,.+)?$', implode('|', array_map('preg_quote', $this->escapeTags($tags)))); | ||
$headers = array($this->tagsHeader => $tagExpression); | ||
$this->invalidator->invalidate($headers); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Make sure that the tags are valid. | ||
* | ||
* @param array $tags The tags to escape. | ||
* | ||
* @return array Sane tags. | ||
*/ | ||
protected function escapeTags(array $tags) | ||
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. i think protected makes sense here, as an extending class might want to use this for other operations. or a special setup might need additional escaping. 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. Ok. |
||
{ | ||
array_walk($tags, function (&$tag) { | ||
$tag = str_replace(array(',', "\n"), array('_', '_'), $tag); | ||
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. we missed doing this before, leading to |
||
}); | ||
|
||
return $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.
this does not render as nicely as expected, because our sphinx setup does not load basic.css but only theme.css - @ddeboer would you know why we do not load default.css and what i could do to get the
into our css, or load basic.css?
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 use the Read the Docs theme (
theme.css
) on local builds too, so you can see what it will really look like. Unfortunately, they don’t support the version directives. Pushed a commit that adds some basic formatting forversionadded/versionchanged
.