Mercurial > piecrust2
comparison piecrust/environment.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 | 1187739e5a19 |
children | c2ca72fb7f0b |
comparison
equal
deleted
inserted
replaced
335:8511137d1b62 | 336:aa6b7ff6a193 |
---|---|
1 import re | 1 import re |
2 import time | 2 import time |
3 import json | 3 import json |
4 import logging | 4 import logging |
5 import hashlib | |
5 import threading | 6 import threading |
6 import contextlib | 7 import contextlib |
7 import collections | 8 import collections |
8 import repoze.lru | 9 import repoze.lru |
9 | 10 |
13 | 14 |
14 re_fs_cache_key = re.compile(r'[^\d\w\-\._]+') | 15 re_fs_cache_key = re.compile(r'[^\d\w\-\._]+') |
15 | 16 |
16 | 17 |
17 def _make_fs_cache_key(key): | 18 def _make_fs_cache_key(key): |
18 return re_fs_cache_key.sub('_', key) | 19 return hashlib.md5(key.encode('utf8')).hexdigest() |
19 | 20 |
20 | 21 |
21 class MemCache(object): | 22 class MemCache(object): |
22 """ Simple memory cache. It can be backed by a simple file-system | 23 """ Simple memory cache. It can be backed by a simple file-system |
23 cache, but items need to be JSON-serializable to do this. | 24 cache, but items need to be JSON-serializable to do this. |