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.
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 🧪
- Swift 🧪
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(…)
In Swift these methods are prefixed with Cache
:
// Invoke the "Get" method
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
- Swift
pub fn set(key: &str, val: Vec<u8>, ttl: i32)
cache.set(key: string, value: string | Uint8Array, ttl: number): void
function cacheSet(key: string, value: ArrayBuffer, ttl: i32): void;
public func CacheSet(key: String, value: String, ttl: Int)
Get​
Get the provided key from the cache.
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
pub fn get(key: &str) -> Result<Vec<u8>, RunErr>
# Get key value as a string
cache.get(key: string): string
# Get raw bytes
cache.getBytes(key: string): Uint8Array
function cacheGet(key: string): ArrayBuffer;
public func CacheGet(key: String) -> String
Additional cache operations are coming soon.