Skip to content

Cache Request

flaui.core.cache_request.CacheRequest(_cs_instance=None)

Python wrapper for FlaUI.Core.CacheRequest.

Initialize CacheRequest.

Accepts either: - None: constructs a new C# CacheRequest() - A C# CacheRequest instance - An Automation wrapper: constructs C# CacheRequest(automation.cs_automation)

Source code in flaui/core/cache_request.py
def __init__(self, _cs_instance: Optional[Any] = None) -> None:
    """Initialize CacheRequest.

    Accepts either:
    - None: constructs a new C# CacheRequest()
    - A C# CacheRequest instance
    - An Automation wrapper: constructs C# CacheRequest(automation.cs_automation)
    """
    if _cs_instance is None:
        self._cs_instance = CSCacheRequest()
    elif isinstance(_cs_instance, Automation):
        # Some FlaUI versions expose only the parameterless constructor.
        # When an Automation wrapper is provided, fall back to a default CacheRequest.
        self._cs_instance = CSCacheRequest()
    else:
        # Assume it's already a C# CacheRequest instance
        self._cs_instance = _cs_instance

automation_element_mode property writable

Get or set the automation element mode.

patterns property

Get or set the patterns.

properties property

Get or set the properties.

tree_filter property writable

Get or set the tree filter.

tree_scope property writable

Get or set the tree scope.

activate()

Activate the cache request. Returns a context manager/disposable.

Source code in flaui/core/cache_request.py
@contextmanager
def activate(self) -> Any:
    """Activate the cache request. Returns a context manager/disposable."""
    disposable = self._cs_instance.Activate()
    try:
        yield
    finally:
        # C# IDisposable typically exposes Dispose()
        try:
            disposable.Dispose()
        except Exception:
            # Fallback if pythonnet provides lowercase method
            try:
                disposable.dispose()
            except Exception:
                logger.debug("Failed to dispose the cache-request activation", exc_info=True)

add(identifier)

Add a pattern or property to the cache request (C# CacheRequest.Add).

C# overloads Add for PatternId and PropertyId; this method accepts either, as the Python :class:~flaui.core.identifiers.PatternId / :class:~flaui.core.identifiers.PropertyId wrappers or as the raw C# identifiers (e.g. automation.cs_automation.PropertyLibrary.Element.Name).

Parameters:

Name Type Description Default
identifier Union[PatternId, PropertyId, Any]

The pattern or property identifier to cache.

required
Source code in flaui/core/cache_request.py
@handle_csharp_exceptions
def add(self, identifier: Union[PatternId, PropertyId, Any]) -> None:
    """Add a pattern or property to the cache request (C# ``CacheRequest.Add``).

    C# overloads ``Add`` for ``PatternId`` and ``PropertyId``; this method accepts either, as the
    Python :class:`~flaui.core.identifiers.PatternId` / :class:`~flaui.core.identifiers.PropertyId`
    wrappers or as the raw C# identifiers (e.g. ``automation.cs_automation.PropertyLibrary.Element.Name``).

    :param identifier: The pattern or property identifier to cache.
    """
    self._cs_instance.Add(identifier.raw if isinstance(identifier, IdentifierBase) else identifier)

add_pattern(pattern)

Add a pattern to the cache request.

Parameters:

Name Type Description Default
pattern Union[PatternId, Any]

The pattern identifier, wrapped or raw C#.

required
Source code in flaui/core/cache_request.py
def add_pattern(self, pattern: Union[PatternId, Any]) -> None:
    """Add a pattern to the cache request.

    :param pattern: The pattern identifier, wrapped or raw C#.
    """
    self.add(pattern)

add_property(property_)

Add a property to the cache request.

Parameters:

Name Type Description Default
property_ Union[PropertyId, Any]

The property identifier, wrapped or raw C#.

required
Source code in flaui/core/cache_request.py
def add_property(self, property_: Union[PropertyId, Any]) -> None:
    """Add a property to the cache request.

    :param property_: The property identifier, wrapped or raw C#.
    """
    self.add(property_)

current() classmethod

Get the current active CacheRequest, if any.

Source code in flaui/core/cache_request.py
@classmethod
def current(cls) -> Optional[CacheRequest]:
    """Get the current active CacheRequest, if any."""
    cs_current = CSCacheRequest.Current
    if cs_current is not None:
        return CacheRequest(_cs_instance=cs_current)
    return None

force_no_cache() classmethod

Force no cache.

Source code in flaui/core/cache_request.py
@classmethod
def force_no_cache(cls) -> Any:
    """Force no cache."""
    return CSCacheRequest.ForceNoCache()

is_caching_active() classmethod

Check if caching is currently active.

Source code in flaui/core/cache_request.py
@classmethod
def is_caching_active(cls) -> bool:
    """Check if caching is currently active."""
    return CSCacheRequest.IsCachingActive

pop() classmethod

Pop the top CacheRequest from the stack.

Source code in flaui/core/cache_request.py
@classmethod
def pop(cls) -> None:
    """Pop the top CacheRequest from the stack."""
    CSCacheRequest.Pop()

push(cache_request) classmethod

Push a CacheRequest onto the stack.

Source code in flaui/core/cache_request.py
@classmethod
def push(cls, cache_request: "CacheRequest") -> None:
    """Push a CacheRequest onto the stack."""
    CSCacheRequest.Push(cache_request._cs_instance)