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 Type
    Method
    Description
    default boolean
    delete(Request request)
    Removes an entry.
    default boolean
    Removes an entry.
    org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSBoolean>
    Removes an entry without waiting.
    org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSBoolean>
    Removes an entry without waiting.
    default Response
    match(Request request)
    Looks up the entry for a request.
    default Response
    Looks up the entry for a URL.
    org.teavm.jso.core.JSPromise<Response>
    Looks up the entry for a request without waiting.
    org.teavm.jso.core.JSPromise<Response>
    Looks up the entry for a URL without waiting.
    default void
    put(Request request, Response response)
    Stores a response.
    default void
    put(String url, Response response)
    Stores a response under a URL.
    org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject>
    putAsync(Request request, Response response)
    Stores a response without waiting, for ctx.waitUntil.
    org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject>
    putAsync(String url, Response response)
    Stores a response under a URL without waiting, for ctx.waitUntil.

    Methods inherited from interface org.teavm.jso.JSObject

    cast
  • Method Details

    • match

      default Response match(Request request)
      Looks up the entry for a request.
      Parameters:
      request - the request, whose URL is the key
      Returns:
      the stored response, or null on a miss
    • match

      default Response match(String url)
      Looks up the entry for a URL.
      Parameters:
      url - the URL
      Returns:
      the stored response, or null on a miss
    • put

      default void put(Request request, Response response)
      Stores a response. Consumes its body; pass Response.copy() when the handler also returns it.
      Parameters:
      request - the request, whose URL is the key; the method must be GET
      response - the response to store
    • put

      default void put(String url, Response response)
      Stores a response under a URL. Consumes its body.
      Parameters:
      url - the URL
      response - the response to store
    • delete

      default boolean delete(Request request)
      Removes an entry.
      Parameters:
      request - the request, whose URL is the key
      Returns:
      whether an entry was there to remove
    • delete

      default boolean delete(String url)
      Removes an entry.
      Parameters:
      url - the URL
      Returns:
      whether an entry was there to remove
    • matchAsync

      org.teavm.jso.core.JSPromise<Response> matchAsync(Request request)
      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 undefined on a miss
    • matchAsync

      org.teavm.jso.core.JSPromise<Response> matchAsync(String url)
      Looks up the entry for a URL without waiting.
      Parameters:
      url - the URL
      Returns:
      a promise of the response, or of undefined on a miss
    • putAsync

      org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> putAsync(Request request, Response response)
      Stores a response without waiting, for ctx.waitUntil.
      Parameters:
      request - the request, whose URL is the key
      response - the response to store
      Returns:
      a promise that settles when the platform is done
    • putAsync

      org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> putAsync(String url, Response response)
      Stores a response under a URL without waiting, for ctx.waitUntil.
      Parameters:
      url - the URL
      response - the response to store
      Returns:
      a promise that settles when the platform is done
    • deleteAsync

      org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSBoolean> deleteAsync(Request request)
      Removes an entry without waiting.
      Parameters:
      request - the request, whose URL is the key
      Returns:
      a promise of whether an entry was removed
    • deleteAsync

      org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSBoolean> deleteAsync(String url)
      Removes an entry without waiting.
      Parameters:
      url - the URL
      Returns:
      a promise of whether an entry was removed