Delegate cache key calculation to CacheKeyController objects

Description

Cache key generation in Element is currently done inside _update_state(), which is intricate and hard to understand. This commit is hopefully a step towards making it more understandable and easier to split up.

Changes proposed in this merge request:

  • Element now owns a __strict_cache_key_obj and __cache_key_obj, instead of storing cache keys itself.
  • A base class CacheKeyController exists, with implementations StrictCacheKeyController and NonStrictCacheKeyController
  • StrictCacheKeyController and NonStrictCacheKeyController objects exist that perform cache key calculation and hold cache keys
  • In strict mode, the __strict_cache_key_obj and __cache_key_obj are the same object.
  • Element._calculate_cache_key has been replaced by Element._get_cache_key_dict, deferring the cache key calculation logic to the CacheKeyController.
    • In doing so, it has grown an ugly workaround for handling the ArtifactElement - it needs special treatment now we're not expecting Elements to generate their own keys. To remove the workaround would require leaving the cache key calculation logic inside the Element, or removing the ArtifactElement (which, as I understand it, was a temporary workaround for the Artifact class).
  • Element._get_strong_key_from_artifact() has been added, because now the CacheKeyController needs to get information from the Element's Artifact.
  • Element._get_strict_cache_key has been added, because now the StrictCacheKeyController needs to get the strict keys of an element's dependencies from outside of the Element class.

This merge request is part of #902 (closed), but will not close it.


Merge request reports

Loading