import { createLogger } from "@open-mercato/shared/lib/logger";
const logger = createLogger("inbox_ops").child({ component: "cache" });
const COUNTS_CACHE_PREFIX = "inbox_ops:counts";
const SETTINGS_CACHE_PREFIX = "inbox_ops:settings";
const COUNTS_CACHE_TTL_MS = 30 * 1e3;
const SETTINGS_CACHE_TTL_MS = 5 * 60 * 1e3;
function createCountsCacheKey(tenantId) {
  return `${COUNTS_CACHE_PREFIX}:${tenantId}`;
}
function createCountsCacheTag(tenantId) {
  return `${COUNTS_CACHE_PREFIX}:${tenantId}`;
}
function createSettingsCacheKey(tenantId) {
  return `${SETTINGS_CACHE_PREFIX}:${tenantId}`;
}
function createSettingsCacheTag(tenantId) {
  return `${SETTINGS_CACHE_PREFIX}:${tenantId}`;
}
async function invalidateCountsCache(cache, tenantId) {
  if (!cache?.deleteByTags) return;
  const tag = createCountsCacheTag(tenantId);
  try {
    await cache.deleteByTags([tag]);
  } catch (err) {
    logger.warn("Failed to invalidate counts cache", { err });
  }
}
async function invalidateSettingsCache(cache, tenantId) {
  if (!cache?.deleteByTags) return;
  const tag = createSettingsCacheTag(tenantId);
  try {
    await cache.deleteByTags([tag]);
  } catch (err) {
    logger.warn("Failed to invalidate settings cache", { err });
  }
}
function resolveCache(container) {
  try {
    return container.resolve("cache");
  } catch {
    return null;
  }
}
export {
  COUNTS_CACHE_TTL_MS,
  SETTINGS_CACHE_TTL_MS,
  createCountsCacheKey,
  createCountsCacheTag,
  createSettingsCacheKey,
  createSettingsCacheTag,
  invalidateCountsCache,
  invalidateSettingsCache,
  resolveCache
};
//# sourceMappingURL=cache.js.map
