Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/constants/public-endpoint-cache.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Public endpoint cache settings.
*
* Keep this file limited to lightweight, reusable constants (no runtime logic).
*/
export const PUBLIC_ENDPOINT_CACHE_SECONDS = {
short: 300,
medium: 3600,
long: 86400,
} as const;

export const PUBLIC_ENDPOINT_CACHE_PRESETS = {
short: {
maxAge: PUBLIC_ENDPOINT_CACHE_SECONDS.short,
type: 'public' as const,
},
medium: {
maxAge: PUBLIC_ENDPOINT_CACHE_SECONDS.medium,
type: 'public' as const,
},
long: {
maxAge: PUBLIC_ENDPOINT_CACHE_SECONDS.long,
type: 'public' as const,
},
} as const;

7 changes: 4 additions & 3 deletions src/middlewares/cache-control.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// src/middlewares/cache-control.middleware.ts
import { Request, Response, NextFunction } from 'express';
import { PUBLIC_ENDPOINT_CACHE_PRESETS } from '../constants/public-endpoint-cache.constants';

/**
* Cache control options for different types of endpoints.
Expand Down Expand Up @@ -90,17 +91,17 @@ export const CachePresets = {
/**
* Short cache for frequently updated public data (5 minutes)
*/
publicShort: { maxAge: 300, type: 'public' as const },
publicShort: PUBLIC_ENDPOINT_CACHE_PRESETS.short,

/**
* Medium cache for moderately stable public data (1 hour)
*/
publicMedium: { maxAge: 3600, type: 'public' as const },
publicMedium: PUBLIC_ENDPOINT_CACHE_PRESETS.medium,

/**
* Long cache for stable public data (24 hours)
*/
publicLong: { maxAge: 86400, type: 'public' as const },
publicLong: PUBLIC_ENDPOINT_CACHE_PRESETS.long,

/**
* Private cache for user-specific data (5 minutes)
Expand Down
8 changes: 3 additions & 5 deletions src/modules/creators/creators.routes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Router } from 'express';
import { httpListCreators } from './creators.controllers';
import {
cacheControl,
CachePresets,
} from '../../middlewares/cache-control.middleware';
import { cacheControl } from '../../middlewares/cache-control.middleware';
import { PUBLIC_ENDPOINT_CACHE_PRESETS } from '../../constants/public-endpoint-cache.constants';

const creatorsRouter = Router();

Expand All @@ -15,7 +13,7 @@ const creatorsRouter = Router();
*/
creatorsRouter.get(
'/',
cacheControl(CachePresets.publicShort),
cacheControl(PUBLIC_ENDPOINT_CACHE_PRESETS.short),
httpListCreators
);

Expand Down
Loading