Files
justanime.fun/src/helper/cache.helper.js
2026-03-01 12:39:28 +05:30

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;
}
};