Mercurial > piecrust2
changeset 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 | 8511137d1b62 |
children | 49408002798e |
files | piecrust/environment.py piecrust/page.py |
diffstat | 2 files changed, 3 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/environment.py Fri Apr 03 11:20:30 2015 -0700 +++ b/piecrust/environment.py Fri Apr 03 11:22:51 2015 -0700 @@ -2,6 +2,7 @@ import time import json import logging +import hashlib import threading import contextlib import collections @@ -15,7 +16,7 @@ def _make_fs_cache_key(key): - return re_fs_cache_key.sub('_', key) + return hashlib.md5(key.encode('utf8')).hexdigest() class MemCache(object):
--- 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),