-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Asset] Add CachedVersionStrategy to decorate any Asset version strategy #36371
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
Conversation
7aa072a
to
6c779c7
Compare
Hello @nicolas-grekas. I'm not sure this is what you expected when you mentioned a "generic |
ae46adb
to
05e694a
Compare
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
@@ -585,6 +585,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode) | ||
->scalarNode('version')->defaultNull()->end() | ||
->scalarNode('version_format')->defaultValue('%%s?%%s')->end() | ||
->scalarNode('json_manifest_path')->defaultNull()->end() | ||
->booleanNode('cache_version')->defaultFalse()->end() |
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.
why not defaultNull
?
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.
I've kept the boolean and removed options.
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.
use_cache
=> true/false/string => when string, it's the name of the cache pool to use?
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 just cache
btw)
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.
I still don't get the name cache_version
cache: true/false
looks better to me. Do I miss something?
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.
I've renamed to cache
.
I wanted to avoid confusion. This cache the result of the URL generation, a developer might think this is the HTTP cache when the browser requests the URL.
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.
cache_json_manifest
then?
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 json_manifest_cache
might even be better?
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.
It can cache any version strategy, not only the manifest.
We could also remove this option and always enable the cache on remote json manifests?
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.
Can we? How would this work with env vars?
Or we might just always enable the cache, even for local files.
For thoughts :)
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Asset/VersionStrategy/CachedVersionStrategy.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Asset/VersionStrategy/CachedVersionStrategy.php
Outdated
Show resolved
Hide resolved
1acd5a3
to
7a43c89
Compare
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.
I've applied all the suggestions.
what about removing the options altogether and deegating them to the cache pool instead?
usingProxyAdapter
, this is quite easy to achieve
How would you insert the decorator between the cache.assets
service and its injection into CachedVersionStrategy
?
@@ -585,6 +585,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode) | ||
->scalarNode('version')->defaultNull()->end() | ||
->scalarNode('version_format')->defaultValue('%%s?%%s')->end() | ||
->scalarNode('json_manifest_path')->defaultNull()->end() | ||
->booleanNode('cache_version')->defaultFalse()->end() |
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.
I've kept the boolean and removed options.
nothing to do here: ppl will know how to redefine the cache.assets service and redefine a dedicated pool if you follow my last comment. |
Nice, that something I'll try to describe in the doc. |
@@ -585,6 +585,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode) | ||
->scalarNode('version')->defaultNull()->end() | ||
->scalarNode('version_format')->defaultValue('%%s?%%s')->end() | ||
->scalarNode('json_manifest_path')->defaultNull()->end() | ||
->booleanNode('cache_version')->defaultFalse()->end() |
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.
I still don't get the name cache_version
cache: true/false
looks better to me. Do I miss something?
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
framework: assets: json_manifest_path: 'https://cdn.example.com/manifest.json' cache_version: true
573bb34
to
fd5a420
Compare
fd5a420
to
7182255
Compare
I'd rather use cache on top of the HttpClient response (see #36858), instead of caching every file version generated by the version strategy. |
Easily add a cache decorator ahead of any
VersionStrategy
. The goal it to cache HTTP requests to a remote JSON manifest.Issues:
applyVersion
callsgetVersion
(like theStaticVersionStrategy
does), we get 2 cache items for a single path.