aiocache icon indicating copy to clipboard operation
aiocache copied to clipboard

Setup cache from URL for decorators

Open jerr0328 opened this issue 4 years ago • 1 comments

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:

  1. 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.
  2. Passing in a Cache object that was set up with Cache.from_url, meaning either a new kwarg or overloading the existing cache arg to take either a class or an object.
  3. 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 the alias 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

jerr0328 avatar Jul 12 '20 10:07 jerr0328

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

argaen avatar Oct 15 '20 14:10 argaen

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.

Dreamsorcerer avatar Jan 02 '23 00:01 Dreamsorcerer