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:
                pass

add_pattern(pattern)

Add a pattern to the cache request.

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

add_property(property_)

Add a property to the cache request.

Source code in flaui/core/cache_request.py
def add_property(self, property_: Any) -> None:
    """Add a property to the cache request."""
    self._cs_instance.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)