Package dev.gmitch215.bytebox.cache
Interface Cache
- All Superinterfaces:
org.teavm.jso.JSObject
public interface Cache
extends org.teavm.jso.JSObject
A Workers cache, from
Caches.defaultCache() or Caches.open(String).
Entries are keyed by request URL and only a GET request can be a key. The cache is
local to the data center the Worker ran in, so an entry put in one location is not there in
another. A response is stored when it is cacheable by its Cache-Control header; the
platform decides, and put returns either way.
The blocking methods wait for the platform. The *Async forms return the promise, for
ctx.waitUntil when a response should not wait on the write.
Cache cache = Caches.defaultCache();
Response hit = cache.match(request);
if (hit == null) cache.put(request, response.copy());
- Since:
- 1.0.3
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanRemoves an entry.default booleanRemoves an entry.org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSBoolean> deleteAsync(Request request) Removes an entry without waiting.org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSBoolean> deleteAsync(String url) Removes an entry without waiting.default ResponseLooks up the entry for a request.default ResponseLooks up the entry for a URL.org.teavm.jso.core.JSPromise<Response> matchAsync(Request request) Looks up the entry for a request without waiting.org.teavm.jso.core.JSPromise<Response> matchAsync(String url) Looks up the entry for a URL without waiting.default voidStores a response.default voidStores a response under a URL.org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> Stores a response without waiting, forctx.waitUntil.org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> Stores a response under a URL without waiting, forctx.waitUntil.Methods inherited from interface org.teavm.jso.JSObject
cast
-
Method Details
-
match
Looks up the entry for a request.- Parameters:
request- the request, whose URL is the key- Returns:
- the stored response, or
nullon a miss
-
match
Looks up the entry for a URL.- Parameters:
url- the URL- Returns:
- the stored response, or
nullon a miss
-
put
Stores a response. Consumes its body; passResponse.copy()when the handler also returns it.- Parameters:
request- the request, whose URL is the key; the method must beGETresponse- the response to store
-
put
Stores a response under a URL. Consumes its body.- Parameters:
url- the URLresponse- the response to store
-
delete
Removes an entry.- Parameters:
request- the request, whose URL is the key- Returns:
- whether an entry was there to remove
-
delete
Removes an entry.- Parameters:
url- the URL- Returns:
- whether an entry was there to remove
-
matchAsync
Looks up the entry for a request without waiting.- Parameters:
request- the request, whose URL is the key- Returns:
- a promise of the response, or of
undefinedon a miss
-
matchAsync
Looks up the entry for a URL without waiting.- Parameters:
url- the URL- Returns:
- a promise of the response, or of
undefinedon a miss
-
putAsync
Stores a response without waiting, forctx.waitUntil.- Parameters:
request- the request, whose URL is the keyresponse- the response to store- Returns:
- a promise that settles when the platform is done
-
putAsync
Stores a response under a URL without waiting, forctx.waitUntil.- Parameters:
url- the URLresponse- the response to store- Returns:
- a promise that settles when the platform is done
-
deleteAsync
Removes an entry without waiting.- Parameters:
request- the request, whose URL is the key- Returns:
- a promise of whether an entry was removed
-
deleteAsync
Removes an entry without waiting.- Parameters:
url- the URL- Returns:
- a promise of whether an entry was removed
-