-
-
Notifications
You must be signed in to change notification settings - Fork 549
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
Exclude sections from static caching (nocache tag) #6231
Merged
Merged
Conversation
This file contains 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
Replacers can modify the initial response The tag pushes its context, contents, and filetype into a cache. It gets replaced with an identifier. The identifier gets replaced with a freshly evaluated view using the tag pair's context and content.
…n for fresh data.
Do I read the code right, that it does support The description is only saying |
Yes it supports full measure now. I thought I had updated the description, but I guess I only mentioned it in the docs. |
# Conflicts: # src/StaticCaching/ServiceProvider.php
This reverts commit e9aeb8f.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Another evolution. This is heavily inspired by #5575, thanks @JohnathonKoster.
This allows half or full measure caching to be enabled, and you can use a
nocache
tag pair to surround chunks of your template that you want to be dynamic.Replacers
The key feature of this PR is the new concept of "replacers", inspired by https://github.com/spatie/laravel-responsecache.
This lets a class replace bits of a response.
For example, if you have a
{{ csrf_field }}
in your template, the class will find any instances of the token, and replace it with some string like<csrf-token-placeholder>
. Then on subsequent requests, it will replace it with the user's actual one.The CSRF token replacer is enabled by default. You don't need to use
nocache
tags. It'll just work.The only difference between our replacers and the Spatie version is that ours can modify the initial response in addition to the one that gets cached.
The
nocache
tagWhenever a
nocache
tag is used, the contents of that tag pair as well as the contextual data are stored and replaced with a placeholder string.The "cascading" data is stripped out from the initial request, and then on subsequent requests, fresh cascade data is merged back in.
The
nocache
Blade directiveIn Blade, we have no way to "capture" some tag pair contents. So instead of using a tag pair, you'd extract the bits you want to keep uncached into a dedicated view. Then you can use the
@nocache
directive, passing in the view name.Full measure support
Using this feature with full measure caching will require javascript to be enabled.
A little snippet will be injected into the page, and will perform an ajax call to get the no-cached bits. There will be a slight delay or "flash of unstyled content" while the request is happening. You can customize what's there in the meantime, for example an svg loading animation.
Differences from #5575
artisan cache:clear
will actually clear it, regardless of the cache driver.{{ nocache:evaluate region="abc" }}
tag and allowing the parser to replace it, this PR uses the replacer feature.Todo
no_cache
tag tonocache
. It's way easier to type.Invalidationseems unnecessary at the moment, maybe.or document as a caveatthat the csrf token doesn't automatically get replaced when using full measure.