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 if no external cache is connected.
note
Documentation for connecting an external cache to Atmo can be found here.
- Rust
- 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 TypeScript/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
- AssemblyScript 🧪
- Swift 🧪
pub fn set(key: &str, val: Vec<u8>, ttl: i32)
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
- AssemblyScript 🧪
- Swift 🧪
pub fn get(key: &str) -> Result<Vec<u8>, RunErr>
function cacheGet(key: string): ArrayBuffer;
public func CacheGet(key: String) -> String
Additional cache operations are coming soon.