diff options
| author | Factiven <[email protected]> | 2023-09-12 21:45:30 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-09-12 21:45:30 +0700 |
| commit | 701798acaeb28f657bd1420d06253d350eb41b96 (patch) | |
| tree | 6df53eb6c7ae07c5af21bcd6d3a0078b1d196d13 /lib/anify | |
| parent | Create build-test.yml (diff) | |
| download | moopa-701798acaeb28f657bd1420d06253d350eb41b96.tar.xz moopa-701798acaeb28f657bd1420d06253d350eb41b96.zip | |
initial v4 commit
Diffstat (limited to 'lib/anify')
| -rw-r--r-- | lib/anify/info.js | 13 | ||||
| -rw-r--r-- | lib/anify/page.js | 13 |
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/anify/info.js b/lib/anify/info.js index 8978664..e7d4025 100644 --- a/lib/anify/info.js +++ b/lib/anify/info.js @@ -1,5 +1,5 @@ import axios from "axios"; -import cacheData from "memory-cache"; +import redis from "../redis"; export async function fetchInfo(id, key) { try { @@ -15,13 +15,18 @@ export async function fetchInfo(id, key) { export default async function getAnifyInfo(id, key) { try { - const cached = cacheData.get(id); + let cached; + if (redis) { + cached = await redis.get(id); + } if (cached) { - return cached; + return JSON.parse(cached); } else { const data = await fetchInfo(id, key); if (data) { - cacheData.put(id, data, 1000 * 60 * 10); + if (redis) { + await redis.set(id, JSON.stringify(data), "EX", 60 * 10); + } return data; } else { return { message: "Schedule not found" }; diff --git a/lib/anify/page.js b/lib/anify/page.js index 6361230..b2b1207 100644 --- a/lib/anify/page.js +++ b/lib/anify/page.js @@ -1,4 +1,4 @@ -import cacheData from "memory-cache"; +import redis from "../redis"; // Function to fetch new data async function fetchData(id, providerId, chapterId, key) { @@ -21,13 +21,18 @@ export default async function getAnifyPage( key ) { try { - const cached = cacheData.get(chapterId); + let cached; + if (redis) { + cached = await redis.get(chapterId); + } if (cached) { - return cached; + return JSON.parse(cached); } else { const data = await fetchData(mediaId, providerId, chapterId, key); if (!data.error) { - cacheData.put(chapterId, data, 1000 * 60 * 10); + if (redis) { + await redis.set(chapterId, JSON.stringify(data), "EX", 60 * 10); + } return data; } else { return { message: "Manga/Novel not found :(" }; |