CacheStorageBackend Class

The storage of the caches of the Cache API (https://w3c.github.io/ServiceWorker/#cache-objects) of the browsing contexts, e.g. a SQLite database or InMemoryCacheStorageBackend (see BrowsingContextOptions.CacheStorage). The backend stores the named caches of each origin and their entries (request and response pairs, in insertion order); the library implements the API (the matching of the requests, including the Vary header, and the batch operations) and only reads and writes entries.

public abstract class CacheStorageBackend

Remarks

The methods are called on the threads of the event loops of the windows and the workers that use the caches: an implementation must be thread-safe. The changes of a cache (CacheStorageBackend.ApplyBatch) must be atomic. The exceptions reject the promises of the API (with a QuotaExceededError when the batch cannot be written, or an UnknownError).

The cache names are arbitrary strings (possibly empty, with lone surrogates). A deleted cache is removed with its entries: the Cache objects that still use it keep the entries they had in memory.

Constructors

NameDescription
CacheStorageBackend()

CacheStorageBackend()

protected CacheStorageBackend()

No documentation is available.

Methods

NameDescription
ApplyBatch(string, string, IReadOnlyList<long>, IReadOnlyList<CacheEntry>)Changes the entries of a cache atomically (https://w3c.github.io/ServiceWorker/#batch-cache-operations): removes the entries with the ids of removedEntryIds, then appends addedEntries (whose ids are assigned by the backend, greater than the ids of the existing entries).
CreateCache(string, string)Creates an empty cache, and returns true, or returns false when the cache exists.
DeleteCache(string, string)Deletes a cache and its entries, and returns true, or returns false when the cache does not exist.
GetCacheNames(string)Returns the names of the caches of an origin, in creation order (https://w3c.github.io/ServiceWorker/#cache-storage-keys).
GetEntries(string, string, string?)Returns the entries of a cache, in insertion order: all the entries, or the entries whose request URL without its query and its fragment (see CachedRequest.UrlWithoutQuery) is urlWithoutQuery. The library filters the entries further (the query, the method and the Vary header).
GetUsage(string)Returns an estimation of the number of bytes used by the caches of an origin (navigator.storage.estimate()). The default is 0: the usage is not reported.

ApplyBatch(string, string, IReadOnlyList<long>, IReadOnlyList<CacheEntry>)

Changes the entries of a cache atomically (https://w3c.github.io/ServiceWorker/#batch-cache-operations): removes the entries with the ids of removedEntryIds, then appends addedEntries (whose ids are assigned by the backend, greater than the ids of the existing entries).

public abstract void ApplyBatch(string origin, string name, IReadOnlyList<long> removedEntryIds, IReadOnlyList<CacheEntry> addedEntries)

Parameters

origin string
The serialization of the origin.
name string
The name of the cache.
removedEntryIds IReadOnlyList<long>
The ids of the entries to remove.
addedEntries IReadOnlyList<CacheEntry>
The entries to append.

CreateCache(string, string)

Creates an empty cache, and returns true, or returns false when the cache exists.

public abstract bool CreateCache(string origin, string name)

Parameters

origin string
The serialization of the origin.
name string
The name of the cache.

Returns

bool

DeleteCache(string, string)

Deletes a cache and its entries, and returns true, or returns false when the cache does not exist.

public abstract bool DeleteCache(string origin, string name)

Parameters

origin string
The serialization of the origin.
name string
The name of the cache.

Returns

bool

GetCacheNames(string)

Returns the names of the caches of an origin, in creation order (https://w3c.github.io/ServiceWorker/#cache-storage-keys).

public abstract IReadOnlyList<string> GetCacheNames(string origin)

Parameters

origin string
The serialization of the origin (e.g. https://example.com).

Returns

IReadOnlyList<string>

GetEntries(string, string, string?)

Returns the entries of a cache, in insertion order: all the entries, or the entries whose request URL without its query and its fragment (see CachedRequest.UrlWithoutQuery) is urlWithoutQuery. The library filters the entries further (the query, the method and the Vary header).

public abstract IReadOnlyList<CacheEntry> GetEntries(string origin, string name, string? urlWithoutQuery)

Parameters

origin string
The serialization of the origin.
name string
The name of the cache.
urlWithoutQuery string?
The URL of the requests without query and fragment, or null for all the entries.

Returns

IReadOnlyList<CacheEntry>

GetUsage(string)

CacheStorageBackend.cs

Returns an estimation of the number of bytes used by the caches of an origin (navigator.storage.estimate()). The default is 0: the usage is not reported.

public virtual long GetUsage(string origin)

Parameters

origin string
The serialization of the origin.

Returns

long