CachePowers is specifically designed to cater to high-performance use cases, ensuring optimal performance and efficiency. It uses either skill's memory or shared distributed memory. 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. For CacheType.Distributed, the value size is restricted to 256 KB or less. For CacheType.InMemory, the value size is not restricted. Warning There are limits on skills total memory usage, so be careful when handling objects beyond 100MB in size. Skills will restart if memory usage is too high.

    • Optional options: CacheOptions

      CacheOptions.

    Returns Promise<boolean>

Generated using TypeDoc