Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Closed
wants to merge 2 commits into from

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Apr 6, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets #35762 (review)
License MIT
Doc PR WIP

Easily add a cache decorator ahead of any VersionStrategy. The goal it to cache HTTP requests to a remote JSON manifest.

framework:
    assets:
        json_manifest_path: 'https://cdn.example.com/manifest.json'
        cache_version: true

Issues:

  • We can a distinct cache item for each asset url that is generated. Caching the contents of the manifest would be a better idea.
  • If the method applyVersion calls getVersion (like the StaticVersionStrategy does), we get 2 cache items for a single path.
  • I don't find the best configuration to pass cache options (beta, expiration).

@GromNaN
Copy link
Member Author

GromNaN commented Apr 6, 2020

Hello @nicolas-grekas. I'm not sure this is what you expected when you mentioned a "generic CachedManifestVersionStrategy".
This as the benefit of being compatible with any implementation of VersionStrategyInterface. But it makes a call to the cache backend for every asset url that is generated, whereas the manifest is a file that fit in a single cache item.

@nicolas-grekas nicolas-grekas added this to the next milestone Apr 6, 2020
@GromNaN GromNaN force-pushed the cached-version-strategy branch 2 times, most recently from ae46adb to 05e694a Compare April 12, 2020 21:51
@GromNaN GromNaN marked this pull request as ready for review April 12, 2020 22:03
@@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not defaultNull?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or just cache btw)

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache_json_manifest then?

Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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 :)

@GromNaN GromNaN force-pushed the cached-version-strategy branch 2 times, most recently from 1acd5a3 to 7a43c89 Compare April 20, 2020 21:27
Copy link
Member Author

@GromNaN GromNaN left a 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?
using ProxyAdapter, 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()
Copy link
Member Author

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.

@nicolas-grekas
Copy link
Member

How would you insert the decorator between the cache.assets service and its injection into CachedVersionStrategy ?

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.

@GromNaN
Copy link
Member Author

GromNaN commented Apr 23, 2020

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()
Copy link
Member

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?

@GromNaN GromNaN force-pushed the cached-version-strategy branch 2 times, most recently from 573bb34 to fd5a420 Compare May 6, 2020 09:40
@GromNaN GromNaN force-pushed the cached-version-strategy branch from fd5a420 to 7182255 Compare May 6, 2020 09:55
@GromNaN
Copy link
Member Author

GromNaN commented May 19, 2020

I'd rather use cache on top of the HttpClient response (see #36858), instead of caching every file version generated by the version strategy.
Closing this PR.

@GromNaN GromNaN closed this May 19, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
@GromNaN GromNaN deleted the cached-version-strategy branch October 20, 2021 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.