-
Notifications
You must be signed in to change notification settings - Fork 61
[WIP/RFC] Refactored CacheInvalidator into descreet units #153
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
/** | ||
* @var array | ||
*/ | ||
private $handlerFlushRegistry; |
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.
We keep track of handlers that need "flushing"
- Renamed and repurposed CacheInvalidator => CacheManager - CacheManager now delegates to handlers - Added handlers for each use case
8e2cc01
to
8a039e2
Compare
* | ||
* @author David de Boer <[email protected]> | ||
*/ | ||
class CacheInvalidator |
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.
This class must be kept for BC reasons (it can be implemented on top of the new APIs though)
Please write tests for your new code. I think none of your new classes can actually be instantiated without error |
@stof no tests yet as noted in the description. this is just a sketch atm. |
* @param mixed $subject | ||
* @param array $options | ||
*/ | ||
public function invalidate($handlerName, $subject, array $options = array()) |
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.
Besides BC (as mentioned by @stof) a reason to keep invalidatePath()
, invalidateRoute()
, invalidateTags()
etc. is that those methods provide good IDE auto-completion. The same cannot be said of this more generic invalidate()
method.
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 think that a clever IDE (like the one I don't use) is clever enough to complete based on the documented return (i.e. @return HandlerInterface
). Of course you don't get the documentation for the concrete implementation but its a good compromise.
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.
the problem is also with knowing what to call. $handlerName is just a variable, whereas invalidateTags or invalidateRoute is explicit.
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.
Well the exception would be useful here and would enumerate ALL the
possibilities instead of the ones which we happen to define an API for.
On 2015-01-04 17:31, David Buchmann wrote:
In src/CacheManager.php [1]:
- public function __construct($handlers)
- {
- $this->handlers = $handlers;
- }
+- /**
- * Invoke the invalidate on the named cache handler
- * @see CacheHandlerInterface::invaidate
- * @param string $handlerName
- * @param mixed $subject
- * @param array $options
- */
- public function invalidate($handlerName, $subject, array $options
= array())the problem is also with knowing what to call. $handlerName is just a
variable, whereas invalidateTags or invalidateRoute is explicit.Reply to this email directly or view it on GitHub [2].
Links:
[1]
#153 (diff)
[2]
https://github.com/FriendsOfSymfony/FOSHttpCache/pull/153/files#r22440816
sorry dan, but i am really -1 on this one. i don't see any benefit from a user point of view. the arguments you need to pass to invalidate() depend on the type of invalidation (route object, path, tag name, ...) so the client code can not ignore what it does or be reusable for different invalidation concepts. having additional non-standard invalidation methods with this architecture ends us up in CacheManager being a registry where you ask for the right type of invalidator by "service" name (but we pass the parameters, instead of returning the handler so that its method could be called directly). that looks like an antipattern to IOC to me. if there are other methods, lets directly inject a handler for that other method with its custom method names to the class that wants to invalidate. i think the discussion started with object invalidation. architectural, i see the point of not implementing the object handling in the CacheInvalidator - just like the TagManager, this should be an ObjectManager and the flexibility we where discussing in there makes sense. so either we could directly inject an ObjectManager or provide a proxy method invalidateObject on the CacheInvalidator - that proxy method would just be to keep it user friendly and gather all methods in one class (which i guess is a facade to a lot of the FOSHttpCache library, in design pattern speak). |
As we discussed in FriendsOfSymfony/FOSHttpCacheBundle#184 (comment), we agreed to open a PR (this one) on the basis of which we determine whether we
I have to agree with @dbu and I think we should go for the second alternative. I prefer the user-friendliness and explicitness of the facade. |
Thanks for the responses. Concerning the method signatures of the (current) I am not really happy with the So how about:
|
looking again at the CacheManager i see that my assumption that we have a TagManager is wrong. i would agree to move the logic of the invalidateTag method into a TagHandler here in the library (and deprecate setTagsHeader / getTagsHeader but forward to TagHandler for now). in the bundle, most of https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/blob/master/EventListener/TagSubscriber.php could move to an extended TagHandler class that also supports tagging a response. as well as fixing FriendsOfSymfony/FOSHttpCacheBundle#182 to not all act on the subscriber, but the TagHander instead. for the other invalidateX they seem so simple that an additional handler around the proxy client seems too much - just inject the proxy client there if you don't want to use the facade. does that make sense? |
i would explicitly inject a TagHandler to the CacheInvalidator, similar to how we inject the ProxyClient. https://github.com/FriendsOfSymfony/FOSHttpCache/blob/master/src/CacheInvalidator.php#L282-L284 would instead check if $this->tagHandler is set or not. |
I'm just not a fan of mixing (patterns?). If we have a CacheInvalidator where the
Where |
i see the CacheInvalidator as a facade to the various "stuff" that is used to invalidate. those things are so simple that another wrapper is just needless overhead. i think we all agree that we need an ObjectHandler. lets build that one and keep it stand alone. proxying those call through CacheInvalidator has not much value. you know whether you handle objects or not in your code, and we should not encourage mixing objects and other approaches in the same code. the ObjectHandler might want to depend on CacheInvalidator in turn, for doing tags or the like. |
I guess we close this now. |
Usage:
Each handler has its own cache proxy instance. This would allow different cache
implementations to be used simultaneously if required.
NOTE: Tests are currently missing.