Caching
Store and reuse values from API calls, database reads, and other operations.
Quick Example
- TypeScript
- Java
- Go
- .NET
await ductape.cache.create({
name: 'API Responses',
tag: 'api-responses',
description: 'Cache for external API calls',
expiry: 60000 // 1 minute in milliseconds
});
ductape.cacheService().create(Map<String, Object>.of(
"name", "API Responses",
"tag", "api-responses",
"description", "Cache for external API calls",
"expiry", 60000 // 1 minute in milliseconds
));
import "context"
client.Cache.Create(ctx, map[string]any{
"name": "API Responses",
"tag": "api-responses",
"description": "Cache for external API calls",
"expiry": 60000 // 1 minute in milliseconds
});
await await ductape.Cache.CreateAsync(new Dictionary<string, object?>
{
["name"] = "API Responses",
["tag"] = "api-responses",
["description"] = "Cache for external API calls",
["expiry"] = 60000 // 1 minute in milliseconds
});
Creating a Cache
- TypeScript
- Java
- Go
- .NET
await ductape.cache.create({
name: 'User Data Cache',
tag: 'user-data',
description: 'Caches user profile information',
expiry: 300000 // 5 minutes
});
ductape.cacheService().create(Map<String, Object>.of(
"name", "User Data Cache",
"tag", "user-data",
"description", "Caches user profile information",
"expiry", 300000 // 5 minutes
));
import "context"
client.Cache.Create(ctx, map[string]any{
"name": "User Data Cache",
"tag": "user-data",
"description": "Caches user profile information",
"expiry": 300000 // 5 minutes
});
await await ductape.Cache.CreateAsync(new Dictionary<string, object?>
{
["name"] = "User Data Cache",
["tag"] = "user-data",
["description"] = "Caches user profile information",
["expiry"] = 300000 // 5 minutes
});
Cache Fields
| Field | Type | Description |
|---|---|---|
name | string | Display name |
tag | string | Unique identifier |
description | string | What the cache stores |
expiry | number | TTL in milliseconds |
Updating a Cache
- TypeScript
- Java
- Go
- .NET
await ductape.cache.update('user-data', {
name: 'Updated Cache Name',
expiry: 600000 // 10 minutes
});
ductape.cache.update('user-data', Map.of(
"name", "Updated Cache Name",
"expiry", 600000 // 10 minutes
));
client.cache.update('user-data', {
"name": "Updated Cache Name",
"expiry": 600000 // 10 minutes
});
await ductape.cache.update('user-data', {
["name"] = "Updated Cache Name",
["expiry"] = 600000 // 10 minutes
});
Fetching Caches
- TypeScript
- Java
- Go
- .NET
// Get all caches
const caches = await ductape.cache.fetchAll();
// Get specific cache
const cache = await ductape.cache.fetch('user-data');
// Get all caches
Map<String, Object> caches = ductape.cache.fetchAll();
// Get specific cache
Map<String, Object> cache = ductape.cache.fetch('user-data');
// Get all caches
caches := client.cache.fetchAll();
// Get specific cache
cache := client.cache.fetch('user-data');
// Get all caches
var caches = await ductape.cache.fetchAll();
// Get specific cache
var cache = await ductape.cache.fetch('user-data');
Using Cache in Operations
Add the cache parameter when calling operations:
- TypeScript
- Java
- Go
- .NET
await ductape.api.run({
app: 'api-service',
event: 'get_user',
input: { body: { userId: '123' } },
cache: 'user-data' // Uses the cache
});
ductape.api().run(Map<String, Object>.of(
"app", "api-service",
"event", "get_user",
input: Map.of( body: Map.of( "userId", "123" ) ),
"cache", "user-data" // Uses the cache
));
import "context"
client.Api.Run(ctx, map[string]any{
"app": "api-service",
"event": "get_user",
input: { body: { "userId": "123" } },
"cache": "user-data" // Uses the cache
});
await await ductape.Api.RunAsync(new Dictionary<string, object?>
{
["app"] = "api-service",
["event"] = "get_user",
input: { body: { ["userId"] = "123" } },
["cache"] = "user-data" // Uses the cache
});