youknowone / ring

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

Dynamic expire config like expire_callback or expired_at #187

Open sawaca96 opened 2 years ago

sawaca96 commented 2 years ago

I think it would be nice if I could determine the expiration in more various ways or dynamically .

use expire callback

def get_expire():
  # return seconds
  ...

@ring.lru(expire_callback=get_exprie())
def foo():
  return "foo"

use expired_at

expired_at can be cron expressoin or time or datetime.

I think cron expression is very nice.

time and datetime is ambiguous, because it cannot be repeated and can only be used once.

@ring.lru(expired_at=expired_at)
def foo():
  return "foo"