diff options
| author | Factiven <[email protected]> | 2023-09-13 00:45:53 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-13 00:45:53 +0700 |
| commit | 7327a69b55a20b99b14ee0803d6cf5f8b88c45ef (patch) | |
| tree | cbcca777593a8cc4b0282e7d85a6fc51ba517e25 /lib/anify/page.js | |
| parent | Update issue templates (diff) | |
| download | moopa-7327a69b55a20b99b14ee0803d6cf5f8b88c45ef.tar.xz moopa-7327a69b55a20b99b14ee0803d6cf5f8b88c45ef.zip | |
Update v4 - Merge pre-push to main (#71)
* Create build-test.yml
* initial v4 commit
* update: github workflow
* update: push on branch
* Update .github/ISSUE_TEMPLATE/bug_report.md
* configuring next.config.js file
Diffstat (limited to 'lib/anify/page.js')
| -rw-r--r-- | lib/anify/page.js | 13 |
1 files changed, 9 insertions, 4 deletions
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 :(" }; |