comparison 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
comparison
equal deleted inserted replaced
335:8511137d1b62 336:aa6b7ff6a193
249 249
250 250
251 def _do_load_page(app, path, path_mtime): 251 def _do_load_page(app, path, path_mtime):
252 # Check the cache first. 252 # Check the cache first.
253 cache = app.cache.getCache('pages') 253 cache = app.cache.getCache('pages')
254 rel_path = os.path.relpath(path, app.root_dir) 254 cache_path = hashlib.md5(path.encode('utf8')).hexdigest() + '.json'
255 cache_path = "%s.json" % rel_path.replace('/', '_').strip('_')
256 page_time = path_mtime or os.path.getmtime(path) 255 page_time = path_mtime or os.path.getmtime(path)
257 if cache.isValid(cache_path, page_time): 256 if cache.isValid(cache_path, page_time):
258 cache_data = json.loads(cache.read(cache_path), 257 cache_data = json.loads(cache.read(cache_path),
259 object_pairs_hook=collections.OrderedDict) 258 object_pairs_hook=collections.OrderedDict)
260 config = PageConfiguration(values=cache_data['config'], 259 config = PageConfiguration(values=cache_data['config'],