Compass Docs
  • Collections
    • ๐Ÿš€Trending
    • ๐ŸŒฑMinting Now
    • ๐Ÿ“ƒCollection Watchlists
    • ๐Ÿ–ผ๏ธToken Window
    • โ†”๏ธCollection Activity
    • ๐Ÿ†Collection Profit Leaderboard
    • ๐ŸŽจCollection Tokens
    • ๐Ÿ‹Collection Top Holders
    • โ›๏ธCollection Mint History
    • ๐Ÿ”Collection Analytics
  • Wallets
    • ๐Ÿš€Getting started with Wallets
    • ๐Ÿ‘›Wallet overview
    • ๐Ÿ”Wallet Activity with Filtering
    • ๐Ÿ™‹Own Wallets
    • ๐ŸฅžFlips
    • ๐Ÿ‘ฅWallet Groups
    • ๐Ÿ”—Related Wallets
  • Pulse
    • ๐Ÿฅ‡Profit leaderboard
    • ๐Ÿ“ˆCompass Pulse
  • Alerts
    • โฐGetting Started with Alerts
  • Automations
    • ๐Ÿš€Getting Started with Automations
    • ๐Ÿ’ฐWallets
    • ๐Ÿ“˜Key Terms in Automations
    • ๐Ÿ”€Inputs/Outputs
    • ๐ŸงชTesting Automations
    • ๐Ÿš€Set Up Your First Listing Alert
    • ๐Ÿ”ซTriggers
      • Token Received
      • Token Sent
      • Token Bought
      • Token Sold
      • Token Minted
      • Webhook
      • Repeat
      • Token Listed
      • Telegram
      • Trigger Advanced Settings
    • ๐Ÿ’ณPricing
    • โšกCustom Actions
      • @compass/http
      • @compass/api
      • @compass/cache
      • @compass/utils
      • @compass/variables
      • @compass/wallet
Powered by GitBook
On this page
  • Usage
  • API Reference
  • Examples
  1. Automations
  2. Custom Actions

@compass/cache

This package provides functionalities to interact with the Compass cache system. You can retrieve, set and manage cache data.

Usage

import cache from "@compass/cache";

API Reference

cache.get(key: string)

Retrieves a value from the cache. Returns null if the key does not exist.

  • key (required, string): The key to retrieve.

Returns a Promise that resolves with the value associated with the key in the cache.

cache.set(key: string, value: any, ttl: number = 60 * 60)

Sets a value in the cache. If a value already exists for the key, it will be overwritten.

  • key (required, string): The key to set.

  • value (required, any): The value to set.

  • ttl (optional, number): The time to live in seconds. Defaults to 60 minutes (60 * 60).

Returns a Promise that resolves once the key-value pair is successfully stored in the cache.

Examples

To retrieve a value from the cache:

import cache from "@compass/cache";

export default async function() {
    const key = 'myKey';
    const value = await cache.get(key);

    return {
      value,
    }
}

To set a value in the cache:

import cache from "@compass/cache";

export default async function() {
    const key = 'myKey';
    const value = 'Hello, World!';
    const ttl = 60 * 60; // 1 hour

    await cache.set(key, value, ttl);
    
    return {
      success: true,
    }
}
Previous@compass/apiNext@compass/utils

Last updated 1 year ago

โšก