mirror of
https://github.com/JustAnimeCore/HiAnime-Api.git
synced 2026-04-17 22:01:44 +00:00
feature, not a bug
This commit is contained in:
34
src/helper/cache.helper.js
Normal file
34
src/helper/cache.helper.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import axios from "axios";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const CACHE_SERVER_URL = process.env.CACHE_URL || null;
|
||||
|
||||
export const getCachedData = async (key) => {
|
||||
try {
|
||||
if (!CACHE_SERVER_URL) {
|
||||
console.log(CACHE_SERVER_URL);
|
||||
return;
|
||||
}
|
||||
const response = await axios.get(`${CACHE_SERVER_URL}/${key}`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (error.response && error.response.status === 404) {
|
||||
return null;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const setCachedData = async (key, value) => {
|
||||
try {
|
||||
if (!CACHE_SERVER_URL) {
|
||||
return;
|
||||
}
|
||||
await axios.post(CACHE_SERVER_URL, { key, value });
|
||||
} catch (error) {
|
||||
console.error("Error setting cache data:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user