function invalidate_cache
Maturity: 20
Asynchronous function that invalidates the cache by resetting the refresh deadline of the client to None.
File:
/tf/active/vicechatdev/rmcl/api.py
Lines:
393 - 394
393 - 394
Complexity:
simple
simple
Purpose
This function is used to force a cache invalidation by clearing the refresh deadline on the client object. This typically triggers a refresh of cached data (likely file lists or authentication tokens) on the next access. It's part of a caching mechanism where the client maintains a deadline for when cached data should be refreshed, and this function immediately invalidates that deadline.
Source Code
async def invalidate_cache():
(await get_client()).refresh_deadline = None
Return Value
Returns None (implicitly). This is an async function that performs a side effect (modifying the client's refresh_deadline attribute) but does not return any value.
Dependencies
askstrio
Required Imports
from sync import add_sync
import trio
Usage Example
import trio
from sync import add_sync
# Assuming get_client() is available in scope
async def main():
# Invalidate the cache to force refresh on next access
await invalidate_cache()
print("Cache invalidated")
# Run with trio
trio.run(main)
# Or use the synchronous version created by add_sync decorator
invalidate_cache_sync = invalidate_cache # The decorator creates a sync version
invalidate_cache_sync() # Call synchronously
Best Practices
- This function should be called when you need to force a refresh of cached data, such as after making changes that affect the cached state
- The add_sync decorator creates both async and sync versions of this function, allowing it to be called from both async and sync contexts
- Ensure the client is properly initialized before calling this function, as it depends on get_client() returning a valid client object
- This is a side-effect function that modifies global state (the client's refresh deadline), so use it carefully in concurrent scenarios
- Consider calling this after operations that modify remote state to ensure local cache stays synchronized
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_cache_buster 47.8% similar
-
function cache_result 47.2% similar
-
function clear_browser_cache_instructions 46.9% similar
-
function touch_static_files 46.4% similar
-
function debug_cache_info 46.0% similar