Accessing cache
Runnables can access an attached cache (such as Redis) using the cache
namespace of the Runnable API. Atmo will configure the cache, and will bind it to the Runnable at runtime.
note
Atmo provides a default in-memory cache when there is no external cache is configured. Refer to the Connections docs to learn how to connect an external cache to Atmo.
- Rust
- JavaScript/TypeScript
- AssemblyScript
In Rust these methods are available under the cache
module:
# Use the "cache" module
use suborbital::cache;
# Invoke the "Get" method
cache::get(…)
In JavaScript and TypeScript the methods live on the cache
import:
import { cache } from "@suborbital/runnable"
cache.get(…)
In AssemblyScript all methods are prefixed with cache
:
// Import then invoke "Get" method
import { cacheGet } from '@suborbital/suborbital'
cacheGet(…)
The following namespace methods are available:
Set
Set a given key's value in the cache. The provided TTL is in seconds.
- Rust
- JavaScript & TypeScript
- AssemblyScript
STATUS: STABLE
pub fn set(key: &str, val: Vec<u8>, ttl: i32)
STATUS: BETA
cache.set(key: string, value: string | Uint8Array, ttl: number): void
STATUS: BETA
function cacheSet(key: string, value: ArrayBuffer, ttl: i32): void;
Get
Get the provided key from the cache.
- Rust
- JavaScript & TypeScript
- AssemblyScript
STATUS: STABLE
pub fn get(key: &str) -> Result<Vec<u8>, RunErr>
STATUS: BETA
# Get key value as a string
cache.get(key: string): string
# Get raw bytes
cache.getBytes(key: string): Uint8Array
STATUS: BETA
function cacheGet(key: string): ArrayBuffer;
Additional cache operations are coming soon.