summaryrefslogtreecommitdiff
path: root/lib/elements/element.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2022-07-16 15:44:01 -0400
committerLex Neva <github.com@lexneva.name>2023-02-18 22:34:16 -0500
commit0e225277dbb57bdaf850a0c67b4fc988051af800 (patch)
treef29a697d6d1ba6b3db914f41a73d1110d53bd2ad /lib/elements/element.py
parente9871d8bc7e837103e31a16067c0a372b932fde8 (diff)
move get_stitch_plan_cache() to utils.cache
Diffstat (limited to 'lib/elements/element.py')
-rw-r--r--lib/elements/element.py21
1 files changed, 3 insertions, 18 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 5df40475..f285258b 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -2,14 +2,10 @@
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-import atexit
-import os
import sys
from copy import deepcopy
import numpy as np
-import appdirs
-import diskcache
import inkex
from inkex import bezier
@@ -21,6 +17,7 @@ from ..svg import (PIXELS_PER_MM, apply_transforms, convert_length,
get_node_transform)
from ..svg.tags import INKSCAPE_LABEL, INKSTITCH_ATTRIBS
from ..utils import Point, cache
+from ..utils.cache import get_stitch_plan_cache
class Param(object):
@@ -396,25 +393,13 @@ class EmbroideryElement(object):
def to_stitch_groups(self, last_patch):
raise NotImplementedError("%s must implement to_stitch_groups()" % self.__class__.__name__)
- @classmethod
- def _get_stitch_plan_cache(cls):
- # one cache, shared by all elements, opened once and closed at program exit
- try:
- return cls._stitch_plan_cache
- except AttributeError:
- cache_dir = os.path.join(appdirs.user_config_dir('inkstitch'), 'cache', 'stitch_plan')
- cls._stitch_plan_cache = diskcache.Cache(cache_dir, size=1024 * 1024 * 100)
- atexit.register(cls._stitch_plan_cache.close)
- return cls._stitch_plan_cache
-
@debug.time
def _load_cached_stitch_groups(self):
- stitch_plan_cache = self._get_stitch_plan_cache()
- return stitch_plan_cache.get(self.node.get('id'))
+ return get_stitch_plan_cache().get(self.node.get('id'))
@debug.time
def _save_cached_stitch_groups(self, stitch_groups):
- stitch_plan_cache = self._get_stitch_plan_cache()
+ stitch_plan_cache = get_stitch_plan_cache()
stitch_plan_cache[self.node.get('id')] = stitch_groups
def embroider(self, last_stitch_group):