bv-ui-core 2.9.2 → 2.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/bvFetch/index.js
CHANGED
@@ -83,14 +83,15 @@ module.exports = function BvFetch ({ shouldCache, cacheName, cacheLimit }) {
|
|
83
83
|
}
|
84
84
|
}).then(() => {
|
85
85
|
if (canBeCached) {
|
86
|
-
const clonedResponse = response.clone()
|
86
|
+
const clonedResponse = response.clone();
|
87
|
+
const sizeCheck = response.clone();
|
87
88
|
const newHeaders = new Headers();
|
88
89
|
clonedResponse.headers.forEach((value, key) => {
|
89
90
|
newHeaders.append(key, value);
|
90
91
|
});
|
91
92
|
newHeaders.append('X-Bazaarvoice-Cached-Time', Date.now())
|
92
93
|
// Get response text to calculate its size
|
93
|
-
|
94
|
+
sizeCheck.text().then(text => {
|
94
95
|
// Calculate size of response text in bytes
|
95
96
|
const sizeInBytes = new Blob([text]).size;
|
96
97
|
|
@@ -166,6 +167,10 @@ module.exports = function BvFetch ({ shouldCache, cacheName, cacheLimit }) {
|
|
166
167
|
// Check if response is available in cache
|
167
168
|
const newPromise = this.fetchFromCache(cacheKey)
|
168
169
|
.then((cachedResponse) => {
|
170
|
+
if (!cachedResponse) {
|
171
|
+
this.cachedUrls.delete(cacheKey)
|
172
|
+
return Promise.resolve(null);
|
173
|
+
}
|
169
174
|
// If response found in cache, return it
|
170
175
|
if (cachedResponse) {
|
171
176
|
return cachedResponse;
|
package/package.json
CHANGED
@@ -140,16 +140,17 @@ describe('BvFetch', function () {
|
|
140
140
|
bvFetchInstance.bvFetchFunc(url, options)
|
141
141
|
.then(response => {
|
142
142
|
// Check if response is fetched from network
|
143
|
-
|
144
|
-
|
143
|
+
setTimeout(() => {
|
144
|
+
expect(response).to.not.be.null;
|
145
|
+
console.log(response.body)
|
145
146
|
|
146
147
|
// Check if caches.match was called
|
147
|
-
|
148
|
+
expect(cacheStub.calledOnce).to.be.false;
|
148
149
|
|
149
150
|
// Check if response is not cached
|
150
|
-
|
151
|
-
|
152
|
-
|
151
|
+
const cachedResponse = cacheStorage.get(url);
|
152
|
+
expect(cachedResponse).to.be.undefined;
|
153
|
+
}, 500)
|
153
154
|
done();
|
154
155
|
})
|
155
156
|
.catch(done);
|