diff piecrust/page.py @ 336:aa6b7ff6a193

internal: Use hashes for cache paths. This will prevent collisions (_e.g._ between `foo/bar` and `foo_bar`), and generating paths that are too long and exceed OS limits.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 03 Apr 2015 11:22:51 -0700
parents ab6e7e0e9d44
children dd25bd3ce1f9
line wrap: on
line diff
--- a/piecrust/page.py	Fri Apr 03 11:20:30 2015 -0700
+++ b/piecrust/page.py	Fri Apr 03 11:22:51 2015 -0700
@@ -251,8 +251,7 @@
 def _do_load_page(app, path, path_mtime):
     # Check the cache first.
     cache = app.cache.getCache('pages')
-    rel_path = os.path.relpath(path, app.root_dir)
-    cache_path = "%s.json" % rel_path.replace('/', '_').strip('_')
+    cache_path = hashlib.md5(path.encode('utf8')).hexdigest() + '.json'
     page_time = path_mtime or os.path.getmtime(path)
     if cache.isValid(cache_path, page_time):
         cache_data = json.loads(cache.read(cache_path),