turbodombuilder - v0.9.22
    Preparing search index...

    Function cache

    • Function

      Parameters

      • Optionaloptions: CacheOptions = {}

        Optional caching configuration to define when to clear it (on event, after timeout, on next frame, on callback, etc.).

      Returns <Type extends object, Value>(
          value:
              | {
                  get?: (this: Type) => Value;
                  set?: (this: Type, value: Value) => void;
              }
              | ((this: Type, ...args: any[]) => any)
              | ((this: Type) => Value),
          context:
              | ClassMethodDecoratorContext<Type, (this: Type, ...args: any) => any>
              | ClassGetterDecoratorContext<Type, Value>
              | ClassAccessorDecoratorContext<Type, Value>,
      ) => any

      cache

      Stage-3 decorator that memorizes expensive reads.

      What it does

      • Method: caches the return value per unique arguments (using a stable key from args).
      • Getter: caches the value once per instance until invalidated.
      • Accessor: wraps the get path like a cached getter; the set path invalidates cached value.
      class IconRenderer {
      #value = 0;

      // Accessor: cached read; any write invalidates immediately
      @cache({clearOnNextFrame: true}) accessor data = {
      get: () => this.#value,
      set: (v: number) => { this.#value = v; }
      };

      // Caches per argument list (e.g., same path ⇒ same result until invalidation)
      @cache({timeout: 5_000}) async loadSvg(path: string): Promise<string> {
      // ...expensive IO
      return fetch(path).then(r => r.text());
      }
      }