Package dev.gmitch215.bytebox.binding
Interface KVNamespace
- All Superinterfaces:
org.teavm.jso.JSObject
public interface KVNamespace
extends org.teavm.jso.JSObject
A Workers KV namespace. Declared with
kv(), named KV by default.
Reads are eventually consistent and cached at the edge for at least 60 seconds. A write is visible in the region that made it straight away and elsewhere within about a minute, so a read-after-write in another region can return the old value.
Every method here blocks and returns a value. Nothing needs a callback or a future.
KVNamespace kv = env.kv();
String visits = kv.get("visits");
kv.put("visits", String.valueOf(visits == null ? 1 : Integer.parseInt(visits) + 1));
- Since:
- 1.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA value and the metadata stored with it.static interfaceOne key in a listing.static interfaceOne page of a key listing. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidRemoves a key.default StringReads a value as text.org.teavm.jso.core.JSPromise<org.teavm.jso.typedarrays.ArrayBuffer> default org.teavm.jso.typedarrays.ArrayBufferReads a value as bytes.default TSObjectReads a value and parses it as JSON.org.teavm.jso.core.JSPromise<KVNamespace.Entry> getMetadata(String key, String type) org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSString> default KVNamespace.EntrygetWithMetadata(String key) Reads a value together with the metadata stored beside it.org.teavm.jso.core.JSPromise<TSObject> getWithType(String key, String type) default KVNamespace.Listinglist()Returns the first page of keys.default KVNamespace.ListingLists keys under a prefix.default KVNamespace.ListingLists keys from where a previous page left off.Returns every key under a prefix, following the cursor until the listing completes.org.teavm.jso.core.JSPromise<KVNamespace.Listing> listKeys(org.teavm.jso.JSObject options) default voidWrites a value.default voidWrites a value that expires.org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> default voidWrites bytes.default voidWrites bytes.org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> default voidputWithMetadata(String key, String value, TSObject metadata) Writes a value with metadata, whichlist()returns without a second read.org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> Methods inherited from interface org.teavm.jso.JSObject
cast
-
Method Details
-
get
Reads a value as text.- Parameters:
key- the key- Returns:
- the value, or
nullwhen the key is absent
-
getJson
Reads a value and parses it as JSON.- Parameters:
key- the key- Returns:
- the parsed value, or
nullwhen the key is absent
-
getBytes
Reads a value as bytes.- Parameters:
key- the key- Returns:
- the bytes, or
nullwhen the key is absent
-
getWithMetadata
Reads a value together with the metadata stored beside it.- Parameters:
key- the key- Returns:
- the value and its metadata;
KVNamespace.Entry.value()isnullwhen absent
-
put
Writes a value.- Parameters:
key- the keyvalue- the value
-
put
Writes a value that expires.- Parameters:
key- the keyvalue- the valuettlSeconds- how long the value lives, at least 60
-
putWithMetadata
Writes a value with metadata, whichlist()returns without a second read.- Parameters:
key- the keyvalue- the valuemetadata- the metadata, at most 1024 bytes once serialised
-
putBytes
Writes bytes.- Parameters:
key- the keyvalue- the bytes
-
putBytes
Writes bytes.- Parameters:
key- the keyvalue- the bytes
-
delete
Removes a key. Succeeds whether or not it was present.- Parameters:
key- the key
-
list
Returns the first page of keys.- Returns:
- the first page of keys
-
list
Lists keys under a prefix.- Parameters:
prefix- the prefix- Returns:
- the first page of matching keys
-
list
Lists keys from where a previous page left off.- Parameters:
prefix- the prefix, ornullfor all keyscursor-KVNamespace.Listing.getCursor()from the previous pagelimit- how many keys to return, at most 1000- Returns:
- the next page
-
listAll
Returns every key under a prefix, following the cursor until the listing completes.- Returns:
- every key under a prefix, following the cursor until the listing completes
-
getText
-
getWithType
-
getBuffer
-
getMetadata
-
putText
-
putText
-
putBuffer
org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> putBuffer(String key, org.teavm.jso.typedarrays.ArrayBuffer value) -
remove
-
listKeys
-