Mercurial > piecrust2
comparison piecrust/appconfig.py @ 948:6c445771a8dc
internal: Fix caching issues with config variants.
Before, changing config variant values could incorrectly re-use a previously
cached config as long as there were the same number of variants.
Now we build a stricter cache hash based on the actual values.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 05 Oct 2017 00:26:25 -0700 |
parents | c0cbcd4752f0 |
children | 45ad976712ec |
comparison
equal
deleted
inserted
replaced
947:a85b2827ba1a | 948:6c445771a8dc |
---|---|
43 "theme applied.") | 43 "theme applied.") |
44 super(PieCrustConfiguration, self).__init__() | 44 super(PieCrustConfiguration, self).__init__() |
45 self._path = path | 45 self._path = path |
46 self._theme_path = theme_path | 46 self._theme_path = theme_path |
47 self._cache = cache or NullCache() | 47 self._cache = cache or NullCache() |
48 self._cache_hash_mod = '' | |
48 self._custom_paths = [] | 49 self._custom_paths = [] |
49 self._post_fixups = [] | 50 self._post_fixups = [] |
50 self.theme_config = theme_config | 51 self.theme_config = theme_config |
51 # Set the values after we set the rest, since our validation needs | 52 # Set the values after we set the rest, since our validation needs |
52 # our attributes. | 53 # our attributes. |
72 def addVariantValue(self, path, value): | 73 def addVariantValue(self, path, value): |
73 def _fixup(config): | 74 def _fixup(config): |
74 set_dict_value(config, path, value) | 75 set_dict_value(config, path, value) |
75 | 76 |
76 self._post_fixups.append(_fixup) | 77 self._post_fixups.append(_fixup) |
78 self._cache_hash_mod += '&val[%s=%s]' % (path, repr(value)) | |
77 | 79 |
78 def setAll(self, values, validate=False): | 80 def setAll(self, values, validate=False): |
79 # Override base class implementation | 81 # Override base class implementation |
80 values = self._processConfigs({}, values) | 82 values = self._processConfigs({}, values) |
81 if validate: | 83 if validate: |
100 cache_key_hash = hashlib.md5( | 102 cache_key_hash = hashlib.md5( |
101 ("version=%s&cache=%d" % ( | 103 ("version=%s&cache=%d" % ( |
102 APP_VERSION, CACHE_VERSION)).encode('utf8')) | 104 APP_VERSION, CACHE_VERSION)).encode('utf8')) |
103 for p in paths: | 105 for p in paths: |
104 cache_key_hash.update(("&path=%s" % p).encode('utf8')) | 106 cache_key_hash.update(("&path=%s" % p).encode('utf8')) |
105 cache_key_hash.update( | 107 if self._cache_hash_mod: |
106 ("&fixups=%d" % len(self._post_fixups)).encode('utf8')) | 108 cache_key_hash.update(self._cache_hash_mod.encode('utf8')) |
107 cache_key = cache_key_hash.hexdigest() | 109 cache_key = cache_key_hash.hexdigest() |
108 | 110 |
109 # Check the cache for a valid version. | 111 # Check the cache for a valid version. |
110 if path_times and self._cache.isValid('config.json', path_times): | 112 if path_times and self._cache.isValid('config.json', path_times): |
111 logger.debug("Loading configuration from cache...") | 113 logger.debug("Loading configuration from cache...") |