diff options
| author | Lex Neva <github.com@lexneva.name> | 2022-07-16 15:44:01 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2023-02-18 22:34:16 -0500 |
| commit | 0e225277dbb57bdaf850a0c67b4fc988051af800 (patch) | |
| tree | f29a697d6d1ba6b3db914f41a73d1110d53bd2ad /lib/utils/cache.py | |
| parent | e9871d8bc7e837103e31a16067c0a372b932fde8 (diff) | |
move get_stitch_plan_cache() to utils.cache
Diffstat (limited to 'lib/utils/cache.py')
| -rw-r--r-- | lib/utils/cache.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/utils/cache.py b/lib/utils/cache.py index c0313ebe..46d8ec59 100644 --- a/lib/utils/cache.py +++ b/lib/utils/cache.py @@ -2,14 +2,32 @@ # # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. +import os +import atexit + +import appdirs +import diskcache try: from functools import lru_cache except ImportError: from backports.functools_lru_cache import lru_cache -# simplify use of lru_cache decorator - +# simplify use of lru_cache decorator def cache(*args, **kwargs): return lru_cache(maxsize=None)(*args, **kwargs) + + +__stitch_plan_cache = None + + +def get_stitch_plan_cache(): + global __stitch_plan_cache + + if __stitch_plan_cache is None: + cache_dir = os.path.join(appdirs.user_config_dir('inkstitch'), 'cache', 'stitch_plan') + __stitch_plan_cache = diskcache.Cache(cache_dir, size=1024 * 1024 * 100) + atexit.register(__stitch_plan_cache.close) + + return __stitch_plan_cache |
