CachePowers is specifically designed to cater to high-performance use cases, ensuring optimal performance and efficiency. It uses either skill's memory or a distributed memory designed to perform faster. The expected performance for retrieving or storing cache objects can vary between 10ms to 500ms, depending on the size of the object.

Hierarchy

  • CachePowers

Index

Methods

Methods

Static delete

  • delete(key: string, options?: CacheOptions): Promise<boolean>
  • Delete cache based on type and scope in options.

    throws

    {RangeError} when key is too long.

    throws

    {TypeError} when key is missing or is empty.

    example

    Deleting Skill or Organization scope cache from within a skill code

    // Ensure you import DataPowers
    import { CacheType, CacheOptions, CachePowers, CacheScope } from "@andi/powers";
    await CachePowers.delete("keyName", { type: CacheType.InMemory });
    await CachePowers.delete("keyName", { scope: CacheScope.Organization });

    Parameters

    • key: string

      Name of key. Max length for key is 256 characters.

    • Optional options: CacheOptions

      CacheOptions.

    Returns Promise<boolean>

Static get

  • Retrieve cache based on type and scope in options. Defaults to CacheType.InMemory and CacheScope.Skill.

    throws

    {RangeError} when key is too long.

    throws

    {TypeError} when key is missing or is empty.

    example

    Getting different types of cache from within your skill code

    // Ensure you import CachePowers
    import { CacheType, CacheOptions, CachePowers, CacheScope } from "@andi/powers";
    
    const key = "my-key-name-here";
    // getting a number
    const counter = await CachePowers.get<number>(key);
    // getting a complex object from different `scope`
    const obj = await CachePowers.get<any>(key, { scope: CacheScope.Organization });

    Type parameters

    • T = unknown

    Parameters

    • key: string

      Name of key. Max length for key is 256 characters.

    • Optional options: CacheOptions

      CacheOptions.

    Returns Promise<T>

Static set

  • set<T>(key: string, value: T, options?: CacheOptions): Promise<boolean>
  • Set cache based on type and scope in options. Defaults to CacheType.InMemory and CacheScope.Skill.

    throws

    {RangeError} when key is too long.

    throws

    {RangeError} when value is too large.

    throws

    {TypeError} when key is missing or is empty.

    example

    Setting different types of cache from within your skill code

    // Ensure you import CachePowers
    import { CacheType, CacheOptions, CachePowers, CacheScope } from "@andi/powers";
    
    const key = "my-key-name-here";
    // setting a number
    const counter = await CachePowers.set<number>(key, 10);
    // setting a complex object
    const obj = { test: "a", num: 3 };
    await CachePowers.set(key, obj, { scope: CacheScope.Organization, ttl:8000, type: CacheType.Distributed });

    Type parameters

    • T = unknown

    Parameters

    • key: string

      Name of key. Max length for key is 256 characters.

    • value: T

      Value to store. Max size for the value object is 256 KB.

    • Optional options: CacheOptions

      CacheOptions.

    Returns Promise<boolean>

Generated using TypeDoc