🔍 Code Extractor

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

  • asks
  • trio

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

    Returns a cache-busting string that varies based on the application mode: current timestamp in debug mode or a static version string in production mode.

    From: /tf/active/vicechatdev/vice_ai/complex_app.py
  • function cache_result 47.2% similar

    A decorator factory that creates a caching decorator for function results with a configurable time-to-live (TTL). Currently a placeholder implementation that passes through function calls without actual caching.

    From: /tf/active/vicechatdev/CDocs/controllers/__init__.py
  • function clear_browser_cache_instructions 46.9% similar

    A utility function that prints formatted instructions to the console for clearing browser cache across different web browsers and operating systems.

    From: /tf/active/vicechatdev/vice_ai/dev_tools.py
  • function touch_static_files 46.4% similar

    Updates the modification timestamp of CSS and JavaScript files in a static directory to force browser cache refresh.

    From: /tf/active/vicechatdev/vice_ai/dev_tools.py
  • function debug_cache_info 46.0% similar

    Flask debug endpoint that provides comprehensive cache busting information including static file versions, modification times, and cache buster values.

    From: /tf/active/vicechatdev/vice_ai/app.py
← Back to Browse