colour.utilities.CacheRegistry#
- class colour.utilities.CacheRegistry[source]#
Bases:
objectProvide a registry for managing mapping-based caches.
The registry maintains a collection of named caches that can be registered, cleared, and unregistered. Each cache operates as a dictionary-like mapping for storing key-value pairs.
Attributes
Methods
register_cache()unregister_cache()clear_cache()clear_all_caches()
Examples
>>> cache_registry = CacheRegistry() >>> cache_a = cache_registry.register_cache("Cache A") >>> cache_a["Foo"] = "Bar" >>> cache_b = cache_registry.register_cache("Cache B") >>> cache_b["John"] = "Doe" >>> cache_b["Luke"] = "Skywalker" >>> print(cache_registry) {'Cache A': '1 item(s)', 'Cache B': '2 item(s)'} >>> cache_registry.clear_cache("Cache A") >>> print(cache_registry) {'Cache A': '0 item(s)', 'Cache B': '2 item(s)'} >>> cache_registry.unregister_cache("Cache B") >>> print(cache_registry) {'Cache A': '0 item(s)'} >>> print(cache_b) {}
- property registry: dict#
Getter for the cache registry.
- Returns:
Cache registry containing cached computation results.
- Return type:
- __str__() str[source]#
Return a formatted string representation of the cache registry.
- Returns:
Formatted string representation.
- Return type:
- register_cache(name: str) dict[source]#
Register a new cache with the specified name in the registry.
Examples
>>> cache_registry = CacheRegistry() >>> cache_a = cache_registry.register_cache("Cache A") >>> cache_a["Foo"] = "Bar" >>> cache_b = cache_registry.register_cache("Cache B") >>> cache_b["John"] = "Doe" >>> cache_b["Luke"] = "Skywalker" >>> print(cache_registry) {'Cache A': '1 item(s)', 'Cache B': '2 item(s)'}
- unregister_cache(name: str) None[source]#
Unregister the cache with the specified name from the registry.
- Parameters:
name (str) – Cache name in the registry.
- Return type:
None
Notes
The cache is cleared before being unregistered.
Examples
>>> cache_registry = CacheRegistry() >>> cache_a = cache_registry.register_cache("Cache A") >>> cache_a["Foo"] = "Bar" >>> cache_b = cache_registry.register_cache("Cache B") >>> cache_b["John"] = "Doe" >>> cache_b["Luke"] = "Skywalker" >>> print(cache_registry) {'Cache A': '1 item(s)', 'Cache B': '2 item(s)'} >>> cache_registry.unregister_cache("Cache B") >>> print(cache_registry) {'Cache A': '1 item(s)'} >>> print(cache_b) {}
- clear_cache(name: str) None[source]#
Clear the cache with the specified name.
- Parameters:
name (str) – Cache name in the registry.
- Return type:
None
Examples
>>> cache_registry = CacheRegistry() >>> cache_a = cache_registry.register_cache("Cache A") >>> cache_a["Foo"] = "Bar" >>> print(cache_registry) {'Cache A': '1 item(s)'} >>> cache_registry.clear_cache("Cache A") >>> print(cache_registry) {'Cache A': '0 item(s)'}
- clear_all_caches() None[source]#
Clear all caches in the registry.
Examples
>>> cache_registry = CacheRegistry() >>> cache_a = cache_registry.register_cache("Cache A") >>> cache_a["Foo"] = "Bar" >>> cache_b = cache_registry.register_cache("Cache B") >>> cache_b["John"] = "Doe" >>> cache_b["Luke"] = "Skywalker" >>> print(cache_registry) {'Cache A': '1 item(s)', 'Cache B': '2 item(s)'} >>> cache_registry.clear_all_caches() >>> print(cache_registry) {'Cache A': '0 item(s)', 'Cache B': '0 item(s)'}
- Return type:
None
- __weakref__#
list of weak references to the object