diff --git a/cache.py b/cache.py index 78a7c56a870336aa32d6742a912d34c70039bb7e..261e76231fd25fc43871c9022072e776f3aeae8f 100644 --- a/cache.py +++ b/cache.py @@ -15,36 +15,9 @@ try: else: cacheDir = user_cache_dir('pystencils') diskcache = Memory(cachedir=cacheDir, verbose=False).cache + diskcacheNoFallback = diskcache except ImportError: # fallback to in-memory caching if joblib is not available diskcache = memorycache(maxsize=64) + diskcacheNoFallback = lambda o: o - -# joblibs Memory decorator does not play nicely with sphinx autodoc (decorated functions do not occur in autodoc) -# -> if this script is imported by sphinx we use functools instead -import sys -calledBySphinx = 'sphinx' in sys.modules -if calledBySphinx: - diskcache = memorycache(maxsize=64) - - -# ------------------------ Helper classes to JSON serialize sympy objects ---------------------------------------------- - - -class SympyJSONEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, sp.Basic): - return {"_type": "sp", "str": str(obj)} - else: - super(SympyJSONEncoder, self).default(obj) - - -class SympyJSONDecoder(json.JSONDecoder): - def __init__(self, *args, **kwargs): - json.JSONDecoder.__init__(self, object_hook=self.object_hook, *args, **kwargs) - - def object_hook(self, obj): - if '_type' in obj: - return sp.sympify(obj['str']) - else: - return obj \ No newline at end of file