-
Notifications
You must be signed in to change notification settings - Fork 3
Added support for automatic purging via cache tags #238
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
Open
stooit
wants to merge
16
commits into
8.x-1.x
Choose a base branch
from
feat/cache-keys-purger
base: 8.x-1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f48040e
Emit cache-keys.
stooit b5f0ac9
Functional tag/path/everything purger.
stooit e9c80a7
Rename header.
stooit 6b5d3e6
Remove cruft.
stooit 5c22663
Fix linting.
kepol f54ba5f
Minor wording tweaks.
kepol 89bbdfb
Removed unused variable.
kepol 948782e
Update modules/quant_api/src/Client/QuantClientInterface.php
kepol 2010e9f
Update modules/quant_api/src/Client/QuantClientInterface.php
kepol 644c709
Update modules/quant_purger/src/Entity/QuantPurgeSettings.php
kepol 7fad3c0
Update modules/quant_purger/src/Entity/QuantPurgeSettings.php
kepol d52e394
Rename QuantPurgeSettings to QuantPurgerSettings.
kepol 5d5b59c
Refactoring & renaming for consistency and clarity.
kepol 1b957b4
Major refactoring, renaming and simplification.
kepol ada1da4
Removed todo in schema file.
kepol afc19ff
Fix linting.
kepol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
modules/quant_purger/config/schema/quant_purger.data_types.schema.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| quant_purger_header: | ||
| type: mapping | ||
| label: 'Quant Purger Header' | ||
| mapping: | ||
| field: | ||
| type: string | ||
| translatable: false | ||
| value: | ||
| type: string | ||
| translatable: false |
73 changes: 66 additions & 7 deletions
73
modules/quant_purger/config/schema/quant_purger.schema.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,80 @@ | ||
| # Schema for the configuration files of the purge_queuer_url module. | ||
| quant_purger.settings: | ||
| type: config_object | ||
| label: 'Quant purger settings.' | ||
| label: 'Quant Purger Queuer Settings' | ||
| mapping: | ||
| tag_blacklist: | ||
| label: 'A list of string tags that will not trigger a queue.' | ||
| tag_blocklist: | ||
| label: 'A list of tags that will not get queued.' | ||
| type: sequence | ||
| translatable: false | ||
| sequence: | ||
| type: string | ||
| label: 'String that cannot be present in the ccache tag.' | ||
| label: 'String that cannot be present in the cache tag.' | ||
| translatable: false | ||
| path_blacklist: | ||
| label: 'A list of string patterns that will not get queued.' | ||
| tag_allowlist: | ||
| label: 'A list of tags that can get queued.' | ||
| type: sequence | ||
| translatable: false | ||
| sequence: | ||
| type: string | ||
| label: 'String that can be present in the cache tag.' | ||
| translatable: false | ||
| path_blocklist: | ||
| label: 'A list of paths that will not get queued.' | ||
| type: sequence | ||
| translatable: false | ||
| sequence: | ||
| type: string | ||
| label: 'String that cannot be present in a fully qualified URL.' | ||
| translatable: false | ||
| path_allowlist: | ||
| label: 'A list of paths that can not get queued.' | ||
| type: sequence | ||
| translatable: false | ||
| sequence: | ||
| type: string | ||
| label: 'String that can be present in a fully qualified URL.' | ||
| translatable: false | ||
|
|
||
| quant_purger.settings.*: | ||
| type: config_entity | ||
| label: 'Quant Purger Settings' | ||
| mapping: | ||
|
|
||
| # | ||
| # Instance metadata: | ||
| # | ||
| id: | ||
| type: string | ||
| translatable: false | ||
| name: | ||
| type: string | ||
| translatable: false | ||
| invalidation_type: | ||
| type: string | ||
| translatable: false | ||
|
|
||
| # | ||
| # Performance settings: | ||
| # | ||
| runtime_measurement: | ||
| type: boolean | ||
| translatable: false | ||
| timeout: | ||
| type: float | ||
| translatable: false | ||
| connect_timeout: | ||
| type: float | ||
| translatable: false | ||
| cooldown_time: | ||
| type: float | ||
| translatable: false | ||
| max_requests: | ||
| type: integer | ||
| translatable: false | ||
|
|
||
| # | ||
| # Success resolution: | ||
| # | ||
| http_errors: | ||
| type: boolean | ||
| translatable: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?php | ||
|
|
||
| namespace Drupal\quant_purger\Entity; | ||
|
|
||
| /** | ||
| * Helper class that centralizes string hashing for security and maintenance. | ||
| */ | ||
| class Hash { | ||
|
|
||
| /** | ||
| * Create a hash with the given input and length. | ||
| * | ||
| * @param string $input | ||
| * The input string to be hashed. | ||
| * @param int $length | ||
| * The length of the hash. | ||
| * | ||
| * @return string | ||
| * Cryptographic hash with the given length. | ||
| */ | ||
| protected static function hashInput($input, $length) { | ||
| // MD5 is the fastest algorithm beyond CRC32 (which is 30% faster, but high | ||
| // collision risk), so this is the best bet for now. If collisions are going | ||
| // to be a major problem in the future, we might have to consider a hash DB. | ||
| $hex = md5($input); | ||
| // The produced HEX can be converted to BASE32 number to take less space. | ||
| // For example 5 characters HEX can be stored in 4 characters BASE32. | ||
| $hash = base_convert(substr($hex, 0, ceil($length * 1.25)), 16, 32); | ||
| // Return a hash with consistent length, padding zeroes if needed. | ||
| return strtolower(str_pad(substr($hash, 0, $length), $length, '0', STR_PAD_LEFT)); | ||
| } | ||
|
|
||
| /** | ||
| * Create unique hashes/IDs for a list of cache tag strings. | ||
| * | ||
| * @param string[] $tags | ||
| * Non-associative array cache tags. | ||
| * | ||
| * @return string[] | ||
| * Non-associative array with hashed copies of the given cache tags. | ||
| */ | ||
| public static function cacheTags(array $tags) { | ||
| $hashes = []; | ||
| foreach ($tags as $tag) { | ||
| if (strlen($tag) > 4) { | ||
| $hashes[] = self::hashInput($tag, 4); | ||
| } | ||
| else { | ||
| $hashes[] = $tag; | ||
| } | ||
| } | ||
| return $hashes; | ||
| } | ||
|
|
||
| /** | ||
| * Create a unique hash that identifies this site. | ||
| * | ||
| * @param string $site_name | ||
| * The identifier of the site on QuantCDN. | ||
| * @param string $site_path | ||
| * The path of the site, e.g. 'site/default' or 'site/database_a'. | ||
| * | ||
| * @return string | ||
| * Cryptographic hash that's long enough to be unique. | ||
| */ | ||
| public static function siteIdentifier($site_name, $site_path) { | ||
| return self::hashInput($site_name . $site_path, 16); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would this make sense as a general utility instead of just in quant_purger?
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.
Or not because it's dealing with cache tags?