Mercurial > piecrust2
comparison piecrust/app.py @ 371:c2ca72fb7f0b 2.0.0a8
caching: Use separate caches for config variants and other contexts.
* The `_cache` directory is now organized in multiple "sub-caches" for
different contexts.
* A new context is created when config variants or overrides are applied.
* `serve` context uses a different context that the other commends, to prevent
the `bake` command's output from messing up the preview server (e.g. with
how asset URLs are generated differently between the two).
* Fix a few places where the cache directory was referenced directly.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 03 May 2015 23:59:46 -0700 |
parents | 4b1019bb2533 |
children | e7b865f8f335 |
comparison
equal
deleted
inserted
replaced
370:a1bbe66cba03 | 371:c2ca72fb7f0b |
---|---|
401 self.debug = debug | 401 self.debug = debug |
402 self.theme_site = theme_site | 402 self.theme_site = theme_site |
403 self.plugin_loader = PluginLoader(self) | 403 self.plugin_loader = PluginLoader(self) |
404 | 404 |
405 if cache: | 405 if cache: |
406 self.cache = ExtensibleCache(self.cache_dir) | 406 cache_dir = os.path.join(self.cache_dir, 'default') |
407 self.cache = ExtensibleCache(cache_dir) | |
407 else: | 408 else: |
408 self.cache = NullExtensibleCache() | 409 self.cache = NullExtensibleCache() |
409 | 410 |
410 self.env = env | 411 self.env = env |
411 if self.env is None: | 412 if self.env is None: |
492 | 493 |
493 @cached_property | 494 @cached_property |
494 def cache_dir(self): | 495 def cache_dir(self): |
495 return os.path.join(self.root_dir, CACHE_DIR) | 496 return os.path.join(self.root_dir, CACHE_DIR) |
496 | 497 |
498 @property # Not a cached property because its result can change. | |
499 def sub_cache_dir(self): | |
500 if self.cache.enabled: | |
501 return self.cache.base_dir | |
502 return None | |
503 | |
497 @cached_property | 504 @cached_property |
498 def sources(self): | 505 def sources(self): |
499 defs = {} | 506 defs = {} |
500 for cls in self.plugin_loader.getSources(): | 507 for cls in self.plugin_loader.getSources(): |
501 defs[cls.SOURCE_NAME] = cls | 508 defs[cls.SOURCE_NAME] = cls |
555 for tax in self.taxonomies: | 562 for tax in self.taxonomies: |
556 if tax.name == tax_name: | 563 if tax.name == tax_name: |
557 return tax | 564 return tax |
558 return None | 565 return None |
559 | 566 |
567 def useSubCache(self, cache_name, cache_key): | |
568 cache_hash = hashlib.md5(cache_key.encode('utf8')).hexdigest() | |
569 cache_dir = os.path.join(self.cache_dir, | |
570 '%s_%s' % (cache_name, cache_hash)) | |
571 self._useSubCacheDir(cache_dir) | |
572 | |
573 def _useSubCacheDir(self, cache_dir): | |
574 assert cache_dir | |
575 logger.debug("Moving cache to: %s" % cache_dir) | |
576 self.cache = ExtensibleCache(cache_dir) | |
577 self.env._onSubCacheDirChanged(self) | |
578 | |
560 def _get_dir(self, default_rel_dir): | 579 def _get_dir(self, default_rel_dir): |
561 abs_dir = os.path.join(self.root_dir, default_rel_dir) | 580 abs_dir = os.path.join(self.root_dir, default_rel_dir) |
562 if os.path.isdir(abs_dir): | 581 if os.path.isdir(abs_dir): |
563 return abs_dir | 582 return abs_dir |
564 return None | 583 return None |