Ben Hoyt added the comment: I really like this idea (and am needing this functionality), but I don't think this API (or implementation) is very nice:
1) It means you have to change your function signature to use the timeout feature. 2) Specifying the interval in minutes seems odd (most similar timeouts in Python are specified in seconds). I would love to see an optional timeout=seconds keyword arg to the lru_cache() decorator, or some other way to support this. Raymond, what do you think would be the simplest way to hook this in? One way I think would be nice (and also support other neat things) is to allow you to specify the dict-like object that's used for the cache (defaults to "dict", of course). So the lru_cache signature would change to: def lru_cache(maxsize=100, typed=False, cache=None): ... >From looking at the source, cache would need to support these methods: get, >clear, __setitem__, __contains__, __len__, __delitem__ Would this just work? Or could there be a race condition if __contains__ (key in cache) returned True but then cache.get(key) returned False a bit later? In any case, this seems nice and general to me, and would mean you could implement a simple ExpiringDict() and then pass that as cache=ExpiringDict(expiry_time). Thoughts? ---------- nosy: +benhoyt _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18577> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com