Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
refactor: include method and data in cache key (#2636)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Aug 8, 2020
1 parent ba84de8 commit 83d63a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -142,6 +142,7 @@
"downshift": "^6.0.2",
"electron-window-state": "^5.0.3",
"framer-motion": "^2.1.2",
"hash-wasm": "^3.7.1",
"http2": "^3.3.7",
"i18next": "^19.4.5",
"isomorphic-fetch": "^2.2.1",
Expand Down
5 changes: 4 additions & 1 deletion src/app/services/HttpClient.ts
@@ -1,4 +1,5 @@
import { Contracts, Http } from "@arkecosystem/platform-sdk";
import { md5 } from "hash-wasm";
import fetch from "isomorphic-fetch";

import { Cache } from "./Cache";
Expand Down Expand Up @@ -29,7 +30,9 @@ export class HttpClient extends Http.Request {
url = `${url}?${new URLSearchParams(data.query as any)}`;
}

return this.cache.remember(url, async () => {
const cacheKey: string = await md5(`${method}.${url}.${JSON.stringify(data)}`);

return this.cache.remember(cacheKey, async () => {
let response;

if (method === "GET") {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -11141,6 +11141,11 @@ hash-base@^3.0.0:
readable-stream "^3.6.0"
safe-buffer "^5.2.0"

hash-wasm@^3.7.1:
version "3.7.1"
resolved "https://registry.yarnpkg.com/hash-wasm/-/hash-wasm-3.7.1.tgz#5efd7b78a234eb47613909d9a8e8b78c18fff5a0"
integrity sha512-YqGlyUvkmVlOanueLEESJ3XJSWRloAYGZz8jUWDDfxLKQsAuHRarIBBzDjBanY6AtyZH0cGq6AE0YbFHUc5kAw==

hash.js@1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.3.tgz#340dedbe6290187151c1ea1d777a3448935df846"
Expand Down

0 comments on commit 83d63a9

Please sign in to comment.