duck.html.components.utils.cachingยถ
Module for caching components.
Module Contentsยถ
Functionsยถ
This is a nested function which you can use directly with component classes
without the need of using |
|
Decorator for returning cached components. |
|
Returns a cache key. |
Dataยถ
APIยถ
- duck.html.components.utils.caching.CachedComponent(component_cls: Type, **cache_options)[source]ยถ
This is a nested function which you can use directly with component classes without the need of using
cached_componentdecorator.Example:
cached_btn_func = CachedComponent( Button, namespace="welcome-btn", targets=["id", "text"], ) # Returns function for retrieving or creating the button instance. btn = cached_btn_func(id="my-btn", text="Hello world") btn.is_from_cache() # Returns False for the first time and True otherwise btn.is_a_copy() # Returns True by default.
- exception duck.html.components.utils.caching.ComponentCachingError[source]ยถ
Bases:
ExceptionRaised upon component caching error.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- duck.html.components.utils.caching.DEFAULT_CACHE_BACKENDยถ
โInMemoryCache(โฆ)โ
- duck.html.components.utils.caching.cached_component(targets: Optional[List[Union[str, Callable]]] = None, cache_backend: Optional[Any] = None, expiry: Optional[float] = None, namespace: Optional[Union[str, Callable]] = None, ignore_args: Optional[List[int]] = None, ignore_kwargs: Optional[List[str]] = None, skip_cache_attr: str = 'skip_cache', on_cache_result: Optional[Callable] = None, freeze: bool = False, return_copy: bool = True, _no_caching: bool = False)[source]ยถ
Decorator for returning cached components.
Create a new instance or return a cached instance.
- Parameters:
targets โ
These are component keyword arguments to focus on when caching or a custom caching callable which returns cache value. Example
targets = ["some_keyword_arg", <custom_callable>]cache_backend โ A custom cache backend which implements methods
getandset. If None, default cache backend is used.expiry โ The expiry for cache keys. Defaults to None.
namespace โ Optional string or callable returning a namespace prefix for keys. Use
namespacefor grouping and easy bulky cache invalidation.ignore_args โ Indices to ignore in arguments. For example to ignore first argument when caching,
[0]may be parsed asignore_args.ignore_kwargs โ Keyword arguments keys to ignore when caching.
skip_cache_attr โ Optional component attribute to skip caching (for debugging). This defaults to
skip_cache, meaning, ifcomponent.skip_cache=Truethen, cache is skipped for that component.on_cache_result โ This is a callable that can be executed upon receiving a result from cache. If some data needs to be reinitialized, you can do this here.