From 933519051c92d1eb99510bcfb0fac8fb8f30419d Mon Sep 17 00:00:00 2001
From: Markus Holzer <markus.holzer@fau.de>
Date: Thu, 23 Feb 2023 10:01:48 +0100
Subject: [PATCH] Add cache clearing function

---
 pystencils/__init__.py | 2 ++
 pystencils/cache.py    | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/pystencils/__init__.py b/pystencils/__init__.py
index 4b23e64c7..70ad39e1a 100644
--- a/pystencils/__init__.py
+++ b/pystencils/__init__.py
@@ -8,6 +8,7 @@ from .datahandling import create_data_handling
 from .display_utils import get_code_obj, get_code_str, show_code, to_dot
 from .field import Field, FieldType, fields
 from .config import CreateKernelConfig
+from .cache import clear_cache
 from .kernel_decorator import kernel, kernel_config
 from .kernelcreation import create_kernel, create_staggered_kernel
 from .simp import AssignmentCollection
@@ -27,6 +28,7 @@ __all__ = ['Field', 'FieldType', 'fields',
            'assignment_from_stencil',
            'SymbolCreator',
            'create_data_handling',
+           'clear_cache',
            'kernel', 'kernel_config',
            'x_', 'y_', 'z_',
            'x_staggered', 'y_staggered', 'z_staggered',
diff --git a/pystencils/cache.py b/pystencils/cache.py
index 34db1d658..4d760364e 100644
--- a/pystencils/cache.py
+++ b/pystencils/cache.py
@@ -59,6 +59,14 @@ def sharedmethodcache(cache_id: str):
     return _decorator
 
 
+def clear_cache():
+    """
+    Clears the pystencils cache created by joblib.
+    """
+    memory = Memory(cache_dir, verbose=0)
+    memory.clear(warn=False)
+
+
 # Disable memory cache:
 # disk_cache = lambda o: o
 # disk_cache_no_fallback = lambda o: o
-- 
GitLab