diff --git a/src/pystencils_autodiff/_file_io.py b/src/pystencils_autodiff/_file_io.py
index 0a42e19e3834349c8a0d145c0ebaeb7785057ca9..68071517d731f59d9c2fd6527badacf47b504f9b 100644
--- a/src/pystencils_autodiff/_file_io.py
+++ b/src/pystencils_autodiff/_file_io.py
@@ -7,8 +7,15 @@
 """
 
 """
+import hashlib
+from os.path import exists, join
+
 import jinja2
 
+from pystencils.cpu.cpujit import get_cache_config
+
+_hash = hashlib.md5
+
 
 def read_template_from_file(file):
     return jinja2.Template(read_file(file))
@@ -23,3 +30,11 @@ def read_file(file):
 def write_file(filename, content):
     with open(filename, 'w') as f:
         f.write(content)
+
+
+def write_cached_content(content, suffix):
+    filename = join(get_cache_config()['object_cache'], _hash(content.encode()).hexdigest() + suffix)
+    if not exists(filename):
+        with open(filename, 'w') as f:
+            f.write(content)
+    return filename