add support for redis cache
Closed this issue · 8 comments
Need to add support for caching using redis
Wanted to know if this still needs help
@karthikn82 it would be great if u can add support for redis cache.
Hi, I'm new to open-source dev. Please let me know if this is still open. If it is, where and how should I start?
@sahven hope this a great first step for you. You can start with this open issue: https://github.com/iamsinghrajat/async-cache/issues/4.
Though not relevant to this issue - I was going through the setitem method, and had a doubt. If the key already exists, shouldn't we first move it to the end and then make a call to super().setitem(key, value) ? Please correct me if I am wrong.
@sahven I don't know if i understood you correctly. But if the key already exists we don't make any call to super().setitem(key, value)
. This func
is called only for the first time a key is inserted in the cache
.
Oh, so we can't overwrite the value to an already existing key? Because if we're overwriting the value, then we should move it to the end, right?
Something along the lines of the following -
def __setitem__(self, key, value):
# Check if key already exists, if it does, then first move it to the end
# and then overwrite using super().__setitem__(key,value)
if key in self:
self.move_to_end(key)
super().__setitem__(key, value)
if len(self) > self.maxsize:
oldest = next(iter(self))
del self[oldest]
@sahven yes correct if we had any flow where we overwrite values for a key, this would correct solution. But currently there is no such flow where the value for key is overwritten.