fetchCache | Caching for the Fetch API in the browser | REST library
kandi X-RAY | fetchCache Summary
kandi X-RAY | fetchCache Summary
fetchCache is an extension of the [Fetch API] that allows you to store the responses to fetch requests. This is useful for reducing the bandwidth that your application consumes, or for offline app usage. Responses are stored using any object implementing the [storage interface] such as [localStorage] Note that, due to the limitations of localStorage (or sessionStorage), if using these objects to store responses, only values that can be serialized as a string (including JSON) can be stored.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of fetchCache
fetchCache Key Features
fetchCache Examples and Code Snippets
Community Discussions
Trending Discussions on fetchCache
QUESTION
I am caching data to decrease SQL Server activity.
When I fetch data from SQL Server the first time it is requested, I then use WriteXml
to store it on disk.
Then second time it is requested (i.e. a file called cacheName
exists), I fetch the data with ReadXml
.
The data in SQL Server has only one row with utcDT value of '2012-03-25 02:01' and when I write the DataTable at Code point 1 Test1() shows there is only one row. When I manually inspect Xml file on disk I also see only 1 row.
However, after reading with ReadXml
at code point 2 Test1()
shows 2 such rows!
How is this happening?
...ANSWER
Answered 2020-Feb-17 at 10:50Just in case anyone else has same issue. I found the answer.
My SQL table DateTime columns were originally specified as UnspecifiedLocal, but the data they contain is actually UTC.
In order to save to cache as Xml, I have to create a new DataTable clone from table I fetch from SQL, and change DateTimeMode to UTC , then I copy from the old table to the new (row by row using ItemArray copy).
This is cumbersome but gets rid of the issue.
QUESTION
I have an app that makes a lot of asynchronous fetch
calls, some of which are identical.
I have a function that supersets fetch
(say fetchPlus
), by creating a pseudo-unique identifier per request based on the arguments. That way, I can store the result in sessionStorage
and access it.
ANSWER
Answered 2019-Jun-13 at 00:09 function fetchPlus() {
...
let promise;
if (fetchCacheGet === null) { // The data is not cached
promise = fetch(...arguments)
.then(data => {
return data.json()
.then(content => {
// read the response and cache
fetchCache.setCache(content);
const init = {
'status': 200,
'statusText': 'SuperSmashingGreat!'
};
return new Response(JSON.stringify(content), init); <-- recreate the response and it.
});
}); // Store the result in the cache
} else {
let dataHeaders = {
'status': 200,
'statusText': 'SuperSmashingGreat!'
};
promise = new Response(JSON.stringify(fetchCacheGet), dataHeaders); // Programatically create a Response
}
return promise;
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install fetchCache
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page