KV-backed Durable Object Storage (Legacy·续
Write buffer behavior
The put() method returns a Promise, but most applications can discard this promise without using await. The Promise usually completes immediately, because put() writes to an in-memory write buffer that is flushed to disk asynchronously. However, if an application performs a large number of put() without waiting for any I/O, the write buffer could theoretically grow large enough to cause the isolate to exceed its 128 MB memory limit. To avoid this scenario, such applications should use await on the Promise returned by put(). The system will then apply backpressure onto the application, slowing it down so that the write buffer has time to flush. Using await will disable automatic write coalescing.
list
list(options Object optional):Promise<Map<string, any>>- Returns all keys and values associated with the current Durable Object in ascending sorted order based on the keys' UTF-8 encodings.
- The type of each returned value in the
Map↗︎ will be whatever was previously written for the corresponding key. - Be aware of how much data may be stored in your Durable Object before calling this version of
listwithout options because all the data will be loaded into the Durable Object's memory, potentially hitting its limit. If that is a concern, pass options tolistas documented below.
Supported options
startstring- Key at which the list results should start, inclusive.
startAfterstring- Key after which the list results should start, exclusive. Cannot be used simultaneously with
start. endstring- Key at which the list results should end, exclusive.
prefixstring- Restricts results to only include key-value pairs whose keys begin with the prefix.
reverseboolean- If true, return results in descending order instead of the default ascending order.
- Enabling
reversedoes not change the meaning ofstart,startKey, orendKey.startstill defines the smallest key in lexicographic order that can be returned (inclusive), effectively serving as the endpoint for a reverse-order list.endstill defines the largest key in lexicographic order that the list should consider (exclusive), effectively serving as the starting point for a reverse-order list. limitnumber- Maximum number of key-value pairs to return.
allowConcurrencyboolean- Same as the option to
get(), above. noCacheboolean- Same as the option to
get(), above.
Alarms
getAlarm
getAlarm(options Object optional):Promise<Number | null>- Retrieves the current alarm time (if set) as integer milliseconds since epoch. The alarm is considered to be set if it has not started, or if it has failed and any retry has not begun. If no alarm is set,
getAlarm()returnsnull.
Supported options
- Same options as
get(), but withoutnoCache.
setAlarm
setAlarm(scheduledTime Date | number, options Object optional):Promise- Sets the current alarm time, accepting either a JavaScript
Date, or integer milliseconds since epoch.
If setAlarm() is called with a time equal to or before Date.now(), the alarm will be scheduled for asynchronous execution in the immediate future. If the alarm handler is currently executing in this case, it will not be canceled. Alarms can be set to millisecond granularity and will usually execute within a few milliseconds after the set time, but can be delayed by up to a minute due to maintenance or failures while failover takes place.
deleteAlarm
deleteAlarm(options Object optional):Promise- Deletes the alarm if one exists. Does not cancel the alarm handler if it is currently executing.
Supported options
setAlarm()anddeleteAlarm()support the same options asput(), but withoutnoCache.
Other
deleteAll
deleteAll(options Object optional):Promise- Deletes all stored data, effectively deallocating all storage used by the Durable Object. For Durable Objects with a key-value storage backend,
deleteAll()removes all keys and associated values for an individual Durable Object. For Durable Objects with a SQLite storage backend,deleteAll()removes the entire contents of a Durable Object's private SQLite database, including both SQL data and key-value data. - For Durable Objects with a key-value storage backend, an in-progress
deleteAll()operation can fail, which may leave a subset of data undeleted. Durable Objects with a SQLite storage backend do not have a partialdeleteAll()issue becausedeleteAll()operations are atomic (all or nothing). - For Workers with a compatibility date of
2026-02-24or later,deleteAll()also deletes any active alarm. For earlier compatibility dates,deleteAll()does not delete alarms. UsedeleteAlarm()separately, or enable thedelete_all_deletes_alarmcompatibility flag.
transactionSync
transactionSync(callback):any- Only available when using SQLite-backed Durable Objects.
- Invokes
callback()wrapped in a transaction, and returns its result. - If
callback()throws an exception, the transaction will be rolled back. - The callback must complete synchronously, that is, it should not be declared
asyncnor otherwise return a Promise. Only synchronous storage operations can be part of the transaction. This is intended for use with SQL queries usingctx.storage.sql.exec(), which complete synchronously.
transaction
transaction(closureFunction(txn)):Promise- Runs the sequence of storage operations called on
txnin a single transaction that either commits successfully or aborts. - Explicit transactions are no longer necessary. Any series of write operations with no intervening
awaitwill automatically be submitted atomically, and the system will prevent concurrent events from executing whileawaita read operation (unless you useallowConcurrency: true). Therefore, a series of reads followed by a series of writes (with no other intervening I/O) are automatically atomic and behave like a transaction. txn-
Provides access to the
put(),get(),delete(), andlist()methods documented above to run in the current transaction context. In order to get transactional behavior within a transaction closure, you must call the methods on thetxnObject instead of on the top-levelctx.storageObject.Also supports a
rollback()function that ensures any changes made during the transaction will be rolled back rather than committed. Afterrollback()is called, any subsequent operations on thetxnObject will fail with an exception.rollback()takes no parameters and returns nothing to the caller. - When using the SQLite-backed storage engine, thetxnobject is obsolete. Any storage operations performed directly on thectx.storageobject, including SQL queries usingctx.storage.sql.exec(), will be considered part of the transaction.
sync
sync():Promise- Synchronizes any pending writes to disk.
- This is similar to normal behavior from automatic write coalescing. If there are any pending writes in the write buffer (including those submitted with the
allowUnconfirmedoption), the returned promise will resolve when they complete. If there are no pending writes, the returned promise will be already resolved.
Related resources
- Durable Objects: Easy, Fast, Correct Choose Three ↗︎
- Zero-latency SQLite storage in every Durable Object blog ↗︎
- WebSockets API
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/durable-objects/api/legacy-kv-storage-api/#page","headline":"KV-backed Durable Object Storage (Legacy)","description":"API reference for the legacy KV-backed Durable Objects storage methods, including get, put, delete, and list.","url":"https://developers.cloudflare.com/durable-objects/api/legacy-kv-storage-api/","inLanguage":"en","image":"https://developers.cloudflare.com/durable-objects/api/legacy-kv-storage-api/og.png?v=0ac53bbc0c561561","dateModified":"2026-04-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: API reference for DurableObjectNamespace, which creates IDs and obtains stubs to interact with Durable Objects. title: Durable Object Namespace image: https://developers.cloudflare.com/durable-objects/api/namespace/og.png?v=2d33736d02547d40
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/durable-objects/llms.txt
Use this file to discover all available pages before exploring further.
Docs