mailgun / expiringdict

Dictionary with auto-expiring values for caching purposes.
Apache License 2.0
344 stars 76 forks source link

Add @memoize decorator #31

Open juharris opened 6 years ago

juharris commented 6 years ago

Example:

    @memoize(max_len=250, max_age_seconds=10)
    def fib(n):
        if n == 0:
            return 0
        elif n == 1:
            return 1
        return fib(n - 1) + fib(n - 2)

    assert 280571172992510140037611932413038677189525 == fib(200)

I'll add some docs and bump the version if the feature is wanted.

UPDATE: Not as important now that https://docs.python.org/3/library/functools.html#functools.lru_cache has been added. However, that method doesn't support eviction by age.

juharris commented 5 years ago

Any chance this can get merged?

mailgun-ci commented 5 years ago

Can one of the admins verify this patch?