Skip to content

Tee-ing Cache.put()? #1367

@lukewagner

Description

@lukewagner

IIUC, a common pattern developers would write when lazily populating a Cache would be something like:

event.respondWith(fetch(url).then(response => {
  var responseClone = response.clone();
  cache.put(url, response);
  return responseClone;  
}));

With a new method teePut (placeholder name, better names welcome!) a developer could write:

event.respondWith(fetch(url).then(response => cache.teePut(url, response)));

where teePut returns a Response (or maybe Promise<Response>) that is semantically a clone of the Response given as argument.

In addition to being simpler to write, this might be more optimizable by the browser for two reasons:

  • the constrained form of the tee, compared to a general clone(), may allow less internal copying between source and sink streams
  • if the response clone flows into one of several content sinks that want to cache a processed form of the resource, the explicit tee operation provides a more-direct route from the content sink back to the Cache entry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions