-
Notifications
You must be signed in to change notification settings - Fork 80
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
request tagging mechanisms #33
Comments
It seems we have some confusion here. At this moment, there's no way to set tag headers through configuration, only through annotations. To clarify the current situation:
The last one, invalidating routes, is the only one that can be done through both annotations and configuration. They do tell the same tools what to do: they are both read by the InvalidationListener, which calls the CacheManager to do the actual work. I guess we should add functionality to:
There then remains, however, the divide in the bundle between the (Liip) cache-control functionality and the (Driebit) invalidation functionality. Should we integrate these two more, for instance by moving the invalidation options ( |
given this some thought. i think adding tags over whole url patterns would be useful. maybe just allow to specify arbitrary headers in addition to the cache control headers. then i could tag a whole area of /blog.* and /news.* as my "blog" and invalidate everything related to blog by tag. (if its just one path, i can just as well ban a path pattern). what if the invalidators configuration could additionally/alternatively be told to invalidate a tag or a path instead of a route? so we would have:
the cache control uses the symfony core RequestMatcher mechanism. maybe if we would use the same mechanism for the invalidators, we could get the invalidation based on anything (host, path, route, ...) quite cheap. even if we do, should we mix output headers and invalidation actions or keep them 2 separate configurations? i tend for the second, to make it easier to read things. then again, in a REST application one might indeed have both overlap strongly. |
Keeping cache-control and invalidation together also has its benefits, as it makes clear how the cached content is related to the way it is invalidated. If we move the invalidator config into the rules section, and take into account #35, config would look like: fos_http_cache:
rules:
-
match:
host: ^/blog.*$
controls: { public: true, max_age: 15, s_maxage: 30, last_modified: "-1 hour" }
vary: [Accept-Encoding, Accept-Language]
invalidation:
routes:
other_route: {}
yet_another_route: {}
paths:
- "/some/path"
tags: [ blog, other_stuff ] Should we rename fos_http_cache:
rules:
-
match:
host: ^/blog.*$
headers:
controls: { public: true, max_age: 15, s_maxage: 30, last_modified: "-1 hour" }
vary: [Accept-Encoding, Accept-Language]
invalidation:
... |
this is starting to look a lot better, yes. i just started wondering how we actually handle the http methods here, and start to fear that we currently send out caching headers for POST / PUT / DELETE requests which would make no sense. when we put invalidation into the same ruleset, we will have the oposite issue that we really don't want to invalidate on GET / HEAD requests. if you always need to put the "method" into the match section, things become kind of pointless again. should we hardcode that the cache headers only apply on GET / HEAD and the invalidation on everything else? or a configurable set of operations to not break on somebody sending some nonstandard method to explode our cache? |
In the TagListener, we already make a hard-coded differentiation between safe and non-safe requests. So the In my opinion, setting caching headers based on configuration should work in the same way: set caching headers such as
These params could either default to specific values ( By the way, we can just use coded logic using |
yeah, makes sense. if somebody has a real use case where he needs something more complicated, he can contribute further flexibility. that will make more sense than us trying to dream what would be needed. |
will have a go at this today |
see #65 |
I don’t think we’ve fully solved the invalidators configuration ( What about moving them into Reopening this because entails a possible BC break, so we may want to reach a decision before 1.0. |
sounds right, yes. we should probably look at a full configuration example and re-check everything in there. |
i think the reason i did not put those under looking at the code i see that the InvalidationSubscriber also handles annotations. so we could follow the same pattern as TagSubscriber with the AbstractRuleSubscriber. however, i wonder if we should move all rule matching into a single rule subscriber, regardless whether its tags, invalidation or cache headers. then we see what actions we have for the rule and do them. if we have overlaps (mostly between tags and headers i guess) we match the same rules repeatedly. though, if we do that one rule for one thing would stop the processing for all 3 types. hm, tricky thing. with the current configuration, you would actually expect that to happen but it would not. say i have
both would be executed. if we unify the matcher, we would only do the first rule and miss the header. this might or might not be desired. maybe we really should do |
we can still reuse the code in the Configuration class and the di extension to avoid duplication |
so, what about this configuration? fos_http_cache:
cache_control:
-
match:
...
headers:
...
tags:
-
match:
path: ^/news
tags: [news-section]
invalidators:
-
match:
...
routes:
... the match part would be the same method in Configuration, reused in the DI extension and also the same base class for the listeners. |
(I think the I like it, as it offers a clear separation between the three types of rules offered by the bundle (caching headers, tags, invalidation) but still allows users to write those rules in a consistent manner. Of course, when people start using this bundle in real projects a different config structure may turn out to be more useful: but that's for 2.0. |
why is there a difference between annotations and the configuration for creating tag headers? could these not just be 2 different ways to tell the same tools what they have to do? or is that already the case?
The text was updated successfully, but these errors were encountered: