Class CacheStorage
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The CacheStorage interface represents the storage for Cache objects.
[Value("CacheStorage")]
public class CacheStorage
- Inheritance
-
CacheStorage
- Inherited Members
Remarks
The interface:
Use Open(string) to obtain a Cache instance.
Use Match(Union42, MultiCacheQueryOptions) to check if a given Request is a key in any of the Cache objects that the CacheStorage object tracks.
You can access CacheStorage through the Window.Caches property in windows or through the WorkerGlobalScope.Caches property in workers.
NOTE
CacheStoragealways rejects with aSecurityErroron untrusted origins (i.e., those that aren't using HTTPS, although this definition will likely become more complex in the future.) When testing on Firefox, you can get around this by checking the Enable Service Workers over HTTP (when toolbox is open) option in the Firefox DevTools options/gear menu. Furthermore, becauseCacheStoragerequires file-system access, it may be unavailable in private mode in Firefox.
NOTE
Match(Union42, MultiCacheQueryOptions) is a convenience method. Equivalent functionality to match a cache entry can be implemented by returning an array of cache names from Keys(), opening each cache with Open(string), and matching the one you want with Match(Union42, CacheQueryOptions).
-Using Service Workers
-Cache
-Window.Caches and WorkerGlobalScope.Caches
-Private Browsing / Incognito modes
Constructors
CacheStorage()
public CacheStorage()
Methods
Delete(string)
The delete() method of the CacheStorage interface finds the Cache object matching the cacheName, and if found, deletes the Cache object and returns a {{jsxref("Promise")}} that resolves to true.
If no Cache object is found, it resolves to false.
[Value("delete")]
public Task<bool> Delete(string cacheName)
Parameters
cacheNamestring
Returns
- Task<bool>
a Promise that resolves to
trueif the Cache
object is found and deleted, andfalseotherwise.
Remarks
You can access CacheStorage through the Window.Caches property in windows or through the WorkerGlobalScope.Caches property in workers.
-Using Service Workers
-Cache
-Window.Caches and WorkerGlobalScope.Caches
Has(string)
The has() method of the CacheStorage
interface returns a Promise that resolves to true if a
Cache object matches the cacheName.
[Value("has")]
public Task<bool> Has(string cacheName)
Parameters
cacheNamestring
Returns
Remarks
You can access CacheStorage through the Window.Caches property in windows or through the WorkerGlobalScope.Caches property in workers.
-Using Service Workers
-Cache
-Window.Caches and WorkerGlobalScope.Caches
Keys()
The keys() method of the CacheStorage interface returns a {{jsxref("Promise")}} that will resolve with an array containing strings corresponding to all of the named Cache objects tracked by the CacheStorage object in the order they were created.
Use this method to iterate over a list of all Cache objects.
[Value("keys")]
public Task<List<string>> Keys()
Returns
- Task<List<string>>
a {{jsxref("Promise")}} that resolves with an array of the Cache names inside the CacheStorage object.
Remarks
You can access CacheStorage through the Window.Caches property in windows or through the WorkerGlobalScope.Caches property in workers.
-Using Service Workers
-Cache
-Window.Caches and WorkerGlobalScope.Caches
Match(Union42, MultiCacheQueryOptions)
The match() method of the CacheStorage interface checks if a given Request or URL string is a key for a stored Response.
This method returns a {{jsxref("Promise")}} for a Response, or a {{jsxref("Promise")}} which resolves to undefined if no match is found.
[Value("match")]
public Task<Response> Match(Union42 request, MultiCacheQueryOptions options = null)
Parameters
requestUnion42optionsMultiCacheQueryOptions
Returns
- Task<Response>
a {{jsxref("Promise")}} that resolves to the matching Response. If
no matching response to the specified request is found, the promise resolves
withundefined.
Remarks
You can access CacheStorage through the Window.Caches property in windows or through the WorkerGlobalScope.Caches property in workers.
Cache objects are searched in creation order.
NOTE
caches.match()is a convenience method.
Equivalent functionality is to call Match(Union42, CacheQueryOptions) on each cache (in the order returned by Keys()) until a Response is returned.
-Using Service Workers
-Cache
-Window.Caches and WorkerGlobalScope.Caches
Open(string)
The open() method of the
CacheStorage interface returns a {{jsxref("Promise")}} that resolves to
the Cache object matching the cacheName.
[Value("open")]
public Task<Cache> Open(string cacheName)
Parameters
cacheNamestring
Returns
Remarks
You can access CacheStorage through the Window.Caches property in windows or through the WorkerGlobalScope.Caches property in workers.
NOTE
If the specified Cache does not exist, a new
cache is created with thatcacheNameand a Promise that
resolves to this new Cache object is returned.
-Using Service Workers
-Cache
-Window.Caches and WorkerGlobalScope.Caches