cache.routes.ts•3.78 kB
/**
* Routes for cache management
*/
import { Router } from 'express';
// Import handlers from separate file for better testability
import { statsHandler, clearAllHandler, clearTypeHandler } from './cache.handlers';
const router = Router();
/**
* @swagger
* /cache/stats:
* get:
* summary: Get cache statistics
* description: Retrieve information about the cache system including hit rate, size, and uptime
* tags: [Cache]
* responses:
* 200:
* description: Cache statistics
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* hits:
* type: integer
* description: Number of cache hits
* example: 1250
* misses:
* type: integer
* description: Number of cache misses
* example: 320
* hitRate:
* type: number
* description: Cache hit rate percentage
* example: 79.6
* size:
* type: integer
* description: Number of items in cache
* example: 157
* uptime:
* type: number
* description: Server uptime in seconds
* example: 3762.45
* 500:
* $ref: '#/components/responses/ServerError'
*/
router.get('/stats', statsHandler);
/**
* @swagger
* /cache/clear:
* delete:
* summary: Clear the entire cache
* description: Remove all cached data from the system
* tags: [Cache]
* responses:
* 200:
* description: Cache cleared successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: Cache cleared successfully
* 500:
* $ref: '#/components/responses/ServerError'
*/
router.delete('/clear', clearAllHandler);
/**
* @swagger
* /cache/clear/{type}:
* delete:
* summary: Clear cache for a specific type
* description: Remove cached data for a specific content type
* tags: [Cache]
* parameters:
* - name: type
* in: path
* description: Cache type to clear (top, all, similar, uuid, sources)
* required: true
* schema:
* type: string
* enum: [top, all, similar, uuid, sources]
* responses:
* 200:
* description: Cache cleared successfully for the specified type
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: "Cleared 42 cache entries for type: top"
* 400:
* description: Invalid cache type
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* $ref: '#/components/responses/ServerError'
*/
router.delete('/clear/:type', clearTypeHandler);
export default router;