about summary refs log tree commit diff stats
path: root/ranger/ext/cached_function.py
blob: 6c1c7769bdc9739e014f0c3fe8d2ec71e70a6f4f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.


def cached_function(fnc):
    cache = {}

    def inner_cached_function(*args):
        try:
            return cache[args]
        except Exception:
            value = fnc(*args)
            cache[args] = value
            return value
    inner_cached_function._cache = cache
    return inner_cached_function