drift Docs
Start
What is Drift?
The tour, if you are new here.
Use cases
Whether Drift does your thing.
Getting started
Nothing to deployed, in one command.
Architecture
How a slice is put together.
What it costs
The free grant, four unit prices, two rules.
Build
Canvas
Static sites, same origin as your API.
Tools
Operate
Auth
Route gates, API keys and your account.
Security
Boundaries, sandboxing and hardening.
Troubleshooting
Error codes
What went wrong, and what to do about it.
Legal
Acceptable use
What a slice may not be used for.
Data processing
The DPA, and every sub-processor.

Cache

drift.Backbone.Cache: a key/value store of strings with an optional TTL.

Signatures

Go
Get(key string)                     ([]byte, error)  // RAW bytes, decode yourself
Set(key string, value any, ttlSeconds int) error   // ttl 0 = never expires
Del(key string)                     error          // named `delete` in the other five SDKs

Three ways it differs by language

  • Deletion is Del in Go and delete in the other five: a different identifier, not a re-spelling.
  • Ruby's Cache.set takes its TTL as a required keyword argument: Drift::Backbone::Cache.set(key, value, ttl: 3600). The others take it positionally.
  • Rust's cache::get returns Option<Value>, wrapping the raw value; unwrap it before returning it as a payload.

A JSON string stores its decoded contents, so Cache.Set("greeting", "hi\nthere", 60) stores the nine bytes of hi, a newline, and there, not the literal escape sequence. Anything else you pass (a number, a bool, a map, a struct) stores its JSON text instead, and Get hands that text back for you to parse. Only a value that is genuinely empty, an empty body, an empty string, or null, is refused, alongside an empty key, both with 400 key and value required.

A miss is not an error locally, and it is on a deployed slice.

Get on a name nothing set returns an empty result under drift atomic run. On a deployed slice the same call answers 404, which Go, Python, Node.js, Ruby and PHP all surface as an error rather than an empty value. Branch on the error deployed, not on an empty return, if the two need to be told apart.

Cache is for speed, not durability.

It is capped independently of your tier: 1 MiB per value, 10,000 entries, 64 MiB of total value bytes. Past any of them Set answers 429 rather than evicting anything older to make room. Treat it as data you can always recompute. The Backbone guide has the eviction behaviour.