Lens Scripting API
    Preparing search index...

    FrameCache provides automatic per-frame caching for expensive function calls.

    This utility allows you to wrap expensive methods so that:

    1. The first call in a frame executes the original function and caches the result
    2. Subsequent calls in the same frame return the cached result
    3. The cache is automatically cleared at the start of each new frame

    Usage:

    // Get the singleton instance
    private frameCache = FrameCache.getInstance()

    // Wrap an expensive method
    private getCachedHandOrientation = this.frameCache.wrap(
    'getHandOrientation',
    () => this.computeHandOrientation()
    )

    // Use the cached version
    const orientation = this.getCachedHandOrientation()

    Results in ~0.03ms overhead compared to a simple manual caching solution.
    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    getInstance: () => FrameCache

    Methods

    • Clear all caches managed by this instance

      Returns void

    • Remove a cached function

      Parameters

      • key: string

      Returns boolean

    • Wrap a function with per-frame caching.

      Type Parameters

      • T

      Parameters

      • key: string

        Unique identifier for this cached function

      • fn: () => T

        The expensive function to cache

      Returns CachedFunction<T>

      A cached version of the function

    • Wrap a method with per-frame caching, preserving 'this' context.

      Type Parameters

      • T
      • TContext

      Parameters

      • key: string

        Unique identifier for this cached function

      • context: TContext

        The object context ('this')

      • fn: (this: TContext) => T

        The expensive method to cache

      Returns () => T

      A cached version of the method