Object cache
An ObjectCache is an S3-compatible cache
in front of buckets at another storage provider, such as AWS S3 or R2. It
serves reads from fast local disks and passes writes on to the original
buckets. S3 clients connect to its endpoints, with path-style addressing
and SigV4 signing: an HTTP endpoint in each attached network, and a public
HTTPS endpoint with publicAccess: true. The buckets, and the data, stay at
the origin.
- your appreads, writes →assets
- assetswrites through →AWS S3
Cache a bucket
Section titled “Cache a bucket”Name the origin bucket and the keys the cache uses to reach it:
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: accessKeyId, originSecretAccessKey: secretAccessKey, }, ], cacheTtlSeconds: 3600, publicAccess: true,});The origin keys are write-only: the API stores them encrypted and never
returns them, so they are compared with the previous deploy. Pass them as
Redacted, here read through Config. Creating a cache waits until it is
running, for up to 30 minutes. type rescales in place; cacheTtlSeconds,
evictionPolicy, maxCapacityGb and the other settings update in place
and are applied in the background.
Add buckets
Section titled “Add buckets”buckets is sent on create only. Add buckets to an existing cache as
ObjectCacheBuckets:
yield* BetterStack.Cloud.ObjectCacheBucket("media", { objectProxyId: cache.id, originEndpoint: "https://s3.us-west-2.amazonaws.com", originBucket: "my-media", originRegion: "us-west-2", originAccessKeyId: accessKeyId, originSecretAccessKey: secretAccessKey,});Clients address a bucket by name, which defaults to originBucket.
originPrefix serves one folder of a bucket under its own name.
Private access
Section titled “Private access”Attach the cache to a private network and turn off its public endpoint:
const network = yield* BetterStack.Cloud.Network("private", { ipPrefix: "10.0.0.0", ipPrefixLength: 24,});yield* BetterStack.Cloud.ObjectCache("internal", { type: "OP100", buckets: [ { originEndpoint: "https://s3.us-west-2.amazonaws.com", originBucket: "my-assets", originAccessKeyId: accessKeyId, originSecretAccessKey: secretAccessKey, }, ], networkIds: [network.id], publicAccess: false,});It is not a CDN
Section titled “It is not a CDN”The object cache is read by S3 clients that sign with SigV4. It doesn’t front an HTTP origin such as a server, so it can’t serve a website’s assets to browsers. Websites serve their own assets.
Ownership
Section titled “Ownership”Every object cache this stack creates carries an alchemy entry in its
metadata, which takes one of its 10 metadata slots, so a deploy that lost
track of one finds it again and alchemy nuke lists only Alchemy-created
caches. Buckets have no metadata, so nothing marks them as this stack’s. See
the ObjectCache reference.
Where next
Section titled “Where next”ObjectCachereference,ObjectCacheBucketreference.- Better Stack’s Object cache docs.