The Cache subsystem provides high-performance temporary data storage for frequently accessed information. It supports TTL (Time-To-Live) expiration, automatic cleanup, and various storage backends for different performance and scalability requirements.
Role: In-memory cache connector
Summary: Provides ultra-fast caching using process memory. Ideal for single-node applications requiring maximum performance with automatic memory management.
Setting | Type | Required | Default | Description |
---|---|---|---|---|
No specific settings | any | No | - | RAMCache accepts any settings object |
Example Configuration:
import { SRE } from '@smythos/sre';
SRE.init({
Cache: {
Connector: 'RAM',
Settings: {},
},
});
Use Cases:
Role: Redis-based distributed cache connector
Summary: Provides scalable, distributed caching using Redis server. Supports clustering, persistence, and advanced data structures for high-performance applications.
Setting | Type | Required | Default | Description |
---|---|---|---|---|
name |
string | Yes | - | Redis master name (for Sentinel mode) |
password |
string | Yes | - | Redis authentication password |
hosts |
string | string[] | any[] | Yes | - | Redis host(s) - single host string or array for Sentinel |
prefix |
string | No | - | Key prefix for namespace isolation |
Example Configuration:
import { SRE } from '@smythos/sre';
SRE.init({
Cache: {
Connector: 'Redis',
Settings: {
name: 'mymaster',
password: process.env.REDIS_PASSWORD,
hosts: 'localhost:6379',
prefix: 'myapp:cache:',
},
},
});
Sentinel Configuration:
import { SRE } from '@smythos/sre';
SRE.init({
Cache: {
Connector: 'Redis',
Settings: {
name: 'mymaster',
password: process.env.REDIS_PASSWORD,
hosts: ['sentinel1:26379', 'sentinel2:26379', 'sentinel3:26379'],
},
},
});
Use Cases:
Role: File-based cache connector
Summary: Provides persistent caching using local filesystem storage. Suitable for applications requiring cache persistence across restarts without external dependencies.
Setting | Type | Required | Default | Description |
---|---|---|---|---|
folder |
string | No | ~/.smyth/storage |
Directory path for cache files |
Example Configuration:
import { SRE } from '@smythos/sre';
SRE.init({
Cache: {
Connector: 'LocalStorage',
Settings: {
folder: './data/cache',
},
},
});
Use Cases:
Role: Amazon S3-based cache connector
Summary: Provides cloud-based caching using Amazon S3 storage. Offers unlimited scalability with built-in durability and global accessibility.
Setting | Type | Required | Default | Description |
---|---|---|---|---|
bucketName |
string | Yes | - | S3 bucket name for cache storage |
region |
string | Yes | - | AWS region of the bucket |
accessKeyId |
string | Yes | - | AWS access key ID |
secretAccessKey |
string | Yes | - | AWS secret access key |
Example Configuration:
import { SRE } from '@smythos/sre';
SRE.init({
Cache: {
Connector: 'S3',
Settings: {
bucketName: 'my-app-cache',
region: 'us-east-1',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
},
});
Use Cases:
Performance Notes:
hosts
is a single string, it's treated as a direct Redis connectionhosts
is an array, it's treated as Redis Sentinel configurationname
field is required for Sentinel mode to identify the masterREDIS_PASSWORD
environment variableREDIS_HOSTS
environment variableThe Redis connector supports these environment variables as fallbacks:
REDIS_HOSTS
- Redis host(s) configurationREDIS_PASSWORD
- Redis authentication passwordREDIS_MASTER_NAME
- Redis master name for Sentinel mode