From cf9f341582a2374eaec080e4339f3e68400d935d Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Tue, 26 Sep 2017 14:15:44 +0200
Subject: [PATCH] Moved cache functionality from lbmpy to pystencils

---
 cache.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 cache.py

diff --git a/cache.py b/cache.py
new file mode 100644
index 000000000..43590c58a
--- /dev/null
+++ b/cache.py
@@ -0,0 +1,19 @@
+try:
+    from functools import lru_cache as memorycache
+except ImportError:
+    from backports.functools_lru_cache import lru_cache as memorycache
+
+try:
+    from joblib import Memory
+    diskcache = Memory(cachedir="/tmp/lbmpy", verbose=False).cache
+except ImportError:
+    # fallback to in-memory caching if joblib is not available
+    diskcache = memorycache(maxsize=64)
+
+
+# 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)
-- 
GitLab