Skip to content

Commit

Permalink
Add cache to getExplorer and update axios version
Browse files Browse the repository at this point in the history
  • Loading branch information
Royal-lobster committed Nov 5, 2024
1 parent 1fdc2c0 commit bb97659
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-mugs-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@everipedia/iq-utils": patch
---

Adds cache to getExplorer
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"axios": "^1.7.7",
"axios-cache-interceptor": "^1.6.2",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
31 changes: 31 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions src/lib/wiki-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type MetaData,
Tag,
} from "../schema";
import { setupCache, buildWebStorage } from "axios-cache-interceptor";

// ===============================
// Text and content helpers
Expand Down Expand Up @@ -172,12 +173,19 @@ export function transformAndFilterTags(tags: { id: string }[]): { id: Tag }[] {
// API-related helpers
// ===============================

const api = axios.create({
baseURL: "https://graph.everipedia.org/graphql",
headers: {
"Content-Type": "application/json",
const api = setupCache(
axios.create({
baseURL: "https://graph.everipedia.org/graphql",
headers: {
"Content-Type": "application/json",
},
}),
{
storage: buildWebStorage(localStorage, "axios-cache:"),
ttl: 12 * 60 * 60 * 1000, // 12 hours
interpretHeader: false,
},
});
);

export async function getExplorers() {
const query = `
Expand Down

0 comments on commit bb97659

Please sign in to comment.