feat: add cache flush module

This commit is contained in:
2026-03-25 11:37:06 +07:00
parent 6599fa8f79
commit 794a130562
3 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,8 @@
import { Context } from "elysia";
import { returnWriteResponse } from "../../../helpers/callback/httpResponse";
import { clearHeroBannerService } from "../services/clearHeroBanner.service";
export const clearHeroBannerController = async (ctx: { set: Context["set"] }) => {
const cacheCleared = await clearHeroBannerService();
return returnWriteResponse(ctx.set, 200, "Hero banner cache flushed successfully", cacheCleared);
};

View File

@ -0,0 +1,4 @@
import Elysia from "elysia";
import { clearHeroBannerController } from "./controllers/clearHeroBanner.controller";
export const flushCacheModule = new Elysia({ prefix: "/flush-cache" }).put("/hero-banner", clearHeroBannerController);

View File

@ -0,0 +1,12 @@
import { redisKey } from "../../../config/redis/key";
import { AppError } from "../../../helpers/error/instances/app";
import { redis } from "../../../utils/databases/redis/connection";
export const clearHeroBannerService = async () => {
try {
const cache = await redis.del(redisKey.find((key) => key.name === "HERO_BANNER")?.key || "");
return cache > 0; // Returns true if cache was cleared, false if it was not found
} catch (error) {
throw new AppError(500, "Failed to clear hero banner cache", error);
}
};