youknowone / ring

Python cache interface with clean API and built-in memcache & redis + asyncio support.
http://ring-cache.readthedocs.io/en/latest/
Other
478 stars 37 forks source link

Add a runtime prefix to default cache key #163

Open jojurajan opened 3 years ago

jojurajan commented 3 years ago

I am using ring.redis==0.7.3 for caching function returns and I need to prefix the cache key based on the environment that code is being deployed.

Currently it is not possible to set the key_refactor method during runtime because of the way compose_key method has been implemented. https://github.com/youknowone/ring/blob/0.7.3/ring/func/base.py#L648

Is there a way to specify the key_refactor method during runtime without re-implementing create_key_builder locally?

youknowone commented 3 years ago

I can't see a good solution for now. I think refactoring create_key_builder to class would be the one of the future.

jojurajan commented 3 years ago

Instead of overriding the key_refactor method, I added the custom prefix to _key_prefix value.

In case someone else is looking for this, the gist can be found here

youknowone commented 3 years ago

let me keep this issue open to make them customizable. I think this is lack of feature.