caching - Redis cache updating -
edit2: clarification: code has refresh cache on miss logic. i'm trying reducing number of missed cache hits.
i'm using redis cache api. idea when api receives call first checks cache , if data isn't in cache api fetch , cache afterwards next time.
at moment configuration following:
maxmemory 50mb maxmemory-policy allkeys-lru
that is, use @ 50mb memory, keep trying keys in there , when memory full start deleting least used keys (lru).
now want introduce second category of keys. second category i'm going set expiry time. set mechanism such when these keys expiry mechanism kicks in , refreshes them (and sets new expiry).
how do this?
edit: progress. turns out redis has pub/sub messaging system in particular can dispatch messages on event. 1 of them expiring keys, can enabled such:
notify-keyspace-events ex
i found code can describes blocking python process subscribing redis' messaging system. can changed detect keys expiring , make call api when key expires, , api refresh key.
def work(self, item): requests.get('http://apiurl/?q={param}'.format(param=item['data']))
so precisely asking about.
often, feels way dangerous , out of control. can imagine bunch of different situations under fail.
so, what's better solution?
to expire keys, use redis' built-in expiry mechanism. don't need refresh cache contents on expiry, simplest when code experiences cache miss.
Comments
Post a Comment