Skip to content
betterstack-alchemyUnofficial

Cloud.ObjectCache

Kind ResourceType id BetterStack.Cloud.ObjectCacheSource src/Cloud/ObjectCache.tsLive test gated Lifecycle test runs against the offline mock; a live run exists but is gated behind BETTERSTACK_TEST_CLOUD_BILLABLE=1 because it bills; live runs need the owner's go-ahead (test/Cloud/ObjectCache.test.ts).

A Better Stack Cloud object cache: an S3-compatible cache in front of buckets at another storage provider (AWS S3, R2, …). It serves reads from fast local disks and passes writes on to the original buckets. S3 clients connect to endpoints (an HTTP endpoint in each attached network, plus a public HTTPS endpoint with publicAccess: true), with path-style addressing and SigV4.

An object cache bills by its type for the billing term: monthly by default; annual commits you to paying for a year. Creating one waits until it is running (up to 30 minutes; failed or degraded stops the deploy).

What changes in place: name, metadata, term, cacheTtlSeconds, listingCacheTtlSeconds, evictionPolicy, fsync, maxCapacityGb, publicAccess (update; the API applies them in the background, see configAppliedAt); type (a rescale, waited for until running with the new type); networkIds and firewallIds (attach/detach actions). placementGroupId, publicIpv4, teamId and availabilityZone replace it. buckets is sent on create only; manage buckets after that with ObjectCacheBucket.

Connecting. The attributes carry the S3 keys (accessKeyId, secretAccessKey, Redacted) and the endpoint URLs (endpointUrls; endpoint picks the HTTPS one when there is one), read from the credentials endpoint once the cache is running. Use path-style addressing and SigV4; any region name works. Buckets can have keys of their own (ObjectCacheBucket).

Credentials: the deploy never rotates the keys on its own. Set rotateCredentials to a new value to rotate them once (the previous keys keep working for a day: previousAccessKeyId, rotatingUntil); a rotation done in the console or CLI is read on the next deploy.

Cache an S3 bucket

const cache = yield* BetterStack.Cloud.ObjectCache("assets", {
type: "OP100",
buckets: [
{
originEndpoint: "https://s3.us-west-2.amazonaws.com",
originBucket: "my-assets",
originRegion: "us-west-2",
originAccessKeyId: Redacted.make(process.env.AWS_ACCESS_KEY_ID!),
originSecretAccessKey: Redacted.make(process.env.AWS_SECRET_ACCESS_KEY!),
},
],
cacheTtlSeconds: 3600,
publicAccess: true,
});

Reachable only from a private network

const network = yield* BetterStack.Cloud.Network("private", {
ipPrefix: "10.0.0.0",
ipPrefixLength: 24,
});
const cache = yield* BetterStack.Cloud.ObjectCache("internal", {
type: "OP100",
buckets: [bucket],
networkIds: [network.id],
publicAccess: false,
});

An S3 client in a Cloud.Service

// env: {
// S3_ENDPOINT: cache.endpoint,
// AWS_ACCESS_KEY_ID: cache.accessKeyId,
// AWS_SECRET_ACCESS_KEY: cache.secretAccessKey,
// }

Reference an object cache by id

const existing = BetterStack.Cloud.ObjectCache.lookup({ id: "42" });

Reference an object cache by name (fails with AmbiguousLookup when several share it)

const byName = BetterStack.Cloud.ObjectCache.lookup({ name: "assets-cache" });

buckets ObjectCacheBucketSpec[] required

The buckets to serve at create, from 1 to 20: each maps a bucket name to a bucket at your S3-compatible storage and its keys. Sent on create only: a later change is neither applied nor a replacement. Add, change or remove buckets afterwards with [ObjectCacheBucket](/reference/cloud/objectcachebucket/).

type string required

The object cache's type, such as OP100 (listObjectCacheType lists them). Changing it rescales the object cache in place, and the deploy waits until it is running with the new type.

availabilityZone string

Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.

cacheTtlSeconds number

How long we keep an object in the cache, in seconds, from 60 to 2592000.

evictionPolicy "least_frequently_used" | "least_recently_used" | string

Which cached objects we remove first when the cache is full. - least_frequently_used: Removes the objects read least often, so a frequently read object survives a flood of one-off reads. - least_recently_used: Removes the objects read longest ago, which suits workloads that scan through data.

firewallIds string[]

The ID of the firewall to attach, at most one. The API never returns it, so the stack remembers what it attached. A change detaches the old firewall before attaching the new one, in place. Leaving the prop out keeps whatever is attached; [] detaches it.

fsync boolean

Whether a write waits for the origin. With true, we confirm a write once the origin stored it. With false, we confirm it once it's in the object cache's journal and upload it to the origin later.

listingCacheTtlSeconds number

How long we keep a bucket listing in the cache, in seconds, from 0 to 86400. 0 turns listing caching off.

maxCapacityGb number

The cache space to use, in GB, from 10 to usable_cache_gb. Defaults to usable_cache_gb on create.

metadata CreateObjectCacheRequestMetadataMap

Your tags, as an object of string keys and values. An update replaces every tag.

name string

The object cache's name, at most 255 characters. Defaults to a unique name generated from the stack, stage and logical id.

networkIds string[]

The IDs of the private networks to attach (network.id); clients reach the cache's HTTP endpoint in each. Changes attach and detach in place. Leaving the prop out keeps whatever is attached; [] detaches every network.

placementGroupId string

The ID of your placement group the object cache was created in, or null when the object cache is in none. Can't be changed after the object cache is created.

publicAccess boolean

Whether the object cache also has a public HTTPS endpoint. We apply a change in the background.

publicIpv4 boolean

Whether the object cache has a public IPv4 address. Can't be changed after the object cache is created.

rotateCredentials string

Rotate the credentials: every change of this value after create (for example a date, "2026-12") calls the API's rotate operation once on the next deploy, and the new secrets replace the old ones in the attributes (and so in every env that references them). Leaving it out, or keeping the same value, never rotates. A rotation done in the console or CLI is simply read on the next deploy.

teamId string

Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.

term "monthly" | "annual"

The billing term, monthly (the default) or annual. annual commits you to paying for a year. A change applies at once, in place: billing ends the current term and starts the new one.

accessKeyId Redacted<string> always set

The S3 access key ID (credentials access_key_id).

availabilityZone string always set

Availability zone the resource lives in, such as us-west-2a.

endpoint string always set

The endpoint to give an S3 client: the HTTPS one when there is one, else the first.

endpointUrls string[] always set

The S3 endpoint URLs: an HTTP URL in each attached network, plus the public HTTPS URL with publicAccess (credentials endpoints).

id string always set

The object cache's ID. Pass it to [ObjectCacheBucket](/reference/cloud/objectcachebucket/) as objectProxyId.

previousAccessKeyId string always set

After a rotation: the previous access key ID, still valid until rotatingUntil.

rotatingUntil string always set

After a rotation: until when the previous keys keep working.

secretAccessKey Redacted<string> always set

The S3 secret access key (credentials secret_access_key).

buckets ObjectCacheBucketsItem[]

The buckets to serve, from 1 to 20. Each maps a bucket name to a bucket at your storage provider and its keys. We never return the keys.

cacheTtlSeconds number

How long we keep an object in the cache, in seconds, from 60 to 2592000.

cacheUsedGb number

The cache space in use, in GB.

configAppliedAt string | null

When we last applied the configuration to the object cache. Once config_applied_at is later than your update, the update is in effect. Stays null until we first apply the configuration.

createdAt string

When the object cache was created.

endpoints ObjectCacheEndpoints

Where S3 clients connect, an HTTP endpoint in each attached network and the public HTTPS endpoint when public_access is on. Clients must use path-style addressing and sign requests with SigV4.

evictionPolicy "least_frequently_used" | "least_recently_used"

Which cached objects we remove first when the cache is full. - least_frequently_used: Removes the objects read least often, so a frequently read object survives a flood of one-off reads. - least_recently_used: Removes the objects read longest ago, which suits workloads that scan through data.

firewallIds string[]

The firewall this stack attached (the API never returns it).

fsync boolean

Whether a write waits for the origin. With true, we confirm a write once the origin stored it. With false, we confirm it once it's in the object cache's journal and upload it to the origin later.

listingCacheTtlSeconds number

How long we keep a bucket listing in the cache, in seconds, from 0 to 86400. 0 turns listing caching off.

maxCapacityGb number

The cache space to use, in GB, from 10 to usable_cache_gb. Defaults to usable_cache_gb on create.

metadata ObjectCacheMetadataMap

Your tags, as an object of string keys and values. An update replaces every tag.

name string

The object cache's name, at most 255 characters.

networkIds string[]

The IDs of the networks attached to the object cache.

placementGroupId string | null

The ID of your placement group the object cache was created in, or null when the object cache is in none. Can't be changed after the object cache is created.

publicAccess boolean

Whether the object cache also has a public HTTPS endpoint. We apply a change in the background.

publicIpv4 boolean

Whether the object cache has a public IPv4 address. Can't be changed after the object cache is created.

status string

The object cache's state. - provisioning: We're starting the object cache. - running: The object cache is ready. - degraded: Part of the object cache isn't working. status_message says why. An original bucket that is down leaves the object cache running. - rescaling: We're changing the object cache's type. - failed: We couldn't create the object cache. status_message says why. Create a new one instead. - destroyed: The object cache is destroyed.

statusMessage string | null

Why the object cache failed or is degraded, or null when there's nothing to report.

teamId string

The ID of the team that owns the object cache. Can't be changed after the object cache is created.

term "monthly" | "annual"

The billing term. Defaults to monthly. A change applies at once, from monthly to annual or back. Billing ends the current term and starts the new one. Sending the current term changes nothing. - monthly: Billed every month. - annual: Paid for a year.

type string

The object cache's type, such as OP100.

updatedAt string

When the object cache was last updated.

usableCacheGb number

The cache space of the object cache's type, in GB.

ObjectCache.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.

availabilityZone string

Zone it lives in, such as us-west-2a. Defaults to the credentials' zone.