✨ feat: add cache flush module
This commit is contained in:
@ -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);
|
||||
};
|
||||
4
src/modules/flushCache/index.ts
Normal file
4
src/modules/flushCache/index.ts
Normal 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);
|
||||
12
src/modules/flushCache/services/clearHeroBanner.service.ts
Normal file
12
src/modules/flushCache/services/clearHeroBanner.service.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user