aiocache
aiocache copied to clipboard
Setup cache from URL for decorators
In #428 (PR: #432), the feature to create a cache from URLs was added. I would like to also be able to use this with decorators, which seems to currently not support this. I imagine there's a few ways of tackling this:
- Adding direct support in the decorator. I would imagine a way to define the decorator with a kwarg like
from_url
which would then set up the cache based on the URL passed in. - Passing in a
Cache
object that was set up withCache.from_url
, meaning either a new kwarg or overloading the existingcache
arg to take either a class or an object. - Changing the config structure to allow configuration with URL. For instance, defining a key with just one key/value of
from_url
and the URL (and other options like plugins and serializers of course). This would allow the decorator code to remain unchanged and simply use thealias
feature already implemented.
I'd be happy to open a PR for any option (including something I missed).
Edit: This is also somewhat relevant to #450
Hey @jerr0328, maybe I would go for passing url
param to the decorator and then inside the decorator create the instance with Cache.from_url which would be quite easy.
You make a point about adding support to use urls in the config but this would be a different feature that we can also add.
Feel free to contribute back please, happy to review! :)
I think with #609 in mind, this won't be relevant after that's solved. You'll likely need to pass a cache object to the decorator, which is essentially your option 2.