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 CacheStorageBackendRemarks
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
| Name | Description |
|---|---|
| CacheStorageBackend() |
CacheStorageBackend()
protected CacheStorageBackend()No documentation is available.
Methods
| Name | Description |
|---|---|
| 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
originstring- The serialization of the origin.
namestring- The name of the cache.
removedEntryIdsIReadOnlyList<long>- The ids of the entries to remove.
addedEntriesIReadOnlyList<CacheEntry>- The entries to append.
CreateCache(string, string)
DeleteCache(string, string)
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)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)