/**
 * Cache Invalidation Helper
 * Add to admin routes to clear cache when data changes
 */
const { cache } = require("../middleware/cache");
const logger = require("../config/logger");

/**
 * Invalidate product-related cache
 */
const invalidateProductCache = () => {
  cache.deletePattern("products");
  cache.deletePattern("featured");
  logger.debug("Product cache invalidated");
};

/**
 * Invalidate blog-related cache
 */
const invalidateBlogCache = () => {
  cache.deletePattern("blog");
  logger.debug("Blog cache invalidated");
};

/**
 * Invalidate portfolio-related cache
 */
const invalidatePortfolioCache = () => {
  cache.deletePattern("portfolio");
  logger.debug("Portfolio cache invalidated");
};

/**
 * Invalidate homepage cache
 */
const invalidateHomepageCache = () => {
  cache.deletePattern("homepage");
  logger.debug("Homepage cache invalidated");
};

/**
 * Invalidate all caches
 */
const invalidateAllCache = () => {
  cache.clear();
  logger.info("All cache cleared");
};

module.exports = {
  invalidateProductCache,
  invalidateBlogCache,
  invalidatePortfolioCache,
  invalidateHomepageCache,
  invalidateAllCache,
};
