colour.utilities.CacheRegistry#

class colour.utilities.CacheRegistry[source]#

Bases: object

A registry for mapping-based caches.

Attributes

Methods

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)
{}
__init__()[source]#
property registry: Dict#

Getter property for the cache registry.

Returns:

Cache registry.

Return type:

dict

__str__() str[source]#

Return a formatted string representation of the cache registry.

Returns:

Formatted string representation.

Return type:

str

register_cache(name: str) Dict[source]#

Register a new cache with given name in the registry.

Parameters:

name (str) – Cache name for the registry.

Returns:

Registered cache.

Return type:

dict

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)[source]#

Unregister cache with given name in the registry.

Parameters:

name (str) – Cache name in the registry.

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)[source]#

Clear the cache with given name.

Parameters:

name (str) – Cache name in the registry.

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()[source]#

Clear all the 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)'}
__weakref__#

list of weak references to the object (if defined)