Skip to content
Snippets Groups Projects
Commit f8071a9e authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Add write_cached_content

parent 69e8ca3f
No related branches found
No related tags found
No related merge requests found
...@@ -7,8 +7,15 @@ ...@@ -7,8 +7,15 @@
""" """
""" """
import hashlib
from os.path import exists, join
import jinja2 import jinja2
from pystencils.cpu.cpujit import get_cache_config
_hash = hashlib.md5
def read_template_from_file(file): def read_template_from_file(file):
return jinja2.Template(read_file(file)) return jinja2.Template(read_file(file))
...@@ -23,3 +30,11 @@ def read_file(file): ...@@ -23,3 +30,11 @@ def read_file(file):
def write_file(filename, content): def write_file(filename, content):
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(content) 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment