MCPcopy Create free account
hub / github.com/OneNoteDev/WebClipper / getAndCacheRemoteValue

Method getAndCacheRemoteValue

src/scripts/http/cachedHttp.ts:55–76  ·  view source on GitHub ↗
(key: string, getRemoteValue: GetResponseAsync)

Source from the content-addressed store, hash-verified

53 }
54
55 protected getAndCacheRemoteValue(key: string, getRemoteValue: GetResponseAsync): Promise<TimeStampedData> {
56 if (!key) {
57 throw new Error("key must be a non-empty string, but was: " + key);
58 }
59
60 if (!getRemoteValue) {
61 throw new Error("getRemoteValue must be non-undefined");
62 }
63
64 return getRemoteValue().then((responsePackage) => {
65 let setValue: TimeStampedData = this.setTimeStampedValue(key, responsePackage.parsedResponse);
66 if (!setValue) {
67 // Fresh data from the remote was unavailable
68 this.cache.removeKey(key);
69 }
70 return Promise.resolve(setValue);
71 }).catch((error: OneNoteApi.RequestError) => {
72 // TODO: Don't use OneNoteApi.RequestError
73 this.cache.removeKey(key);
74 return Promise.reject(error);
75 });
76 }
77
78 /**
79 * Returns true if the timestamped data is older than the expiry time; false otherwise.

Callers 1

getFreshValueMethod · 0.95

Calls 2

setTimeStampedValueMethod · 0.95
removeKeyMethod · 0.65

Tested by

no test coverage detected