mirror of
https://github.com/JustAnimeCore/HiAnime-Api.git
synced 2026-04-17 13:51:44 +00:00
35 lines
760 B
JavaScript
35 lines
760 B
JavaScript
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;
|
|
}
|
|
};
|