feat: implement API response caching with node-cache
- Add in-memory cache middleware with configurable TTL - Cache GET endpoints: streets (5min), events (2min), posts (1min), rewards (10min) - Automatic cache invalidation on POST/PUT/DELETE operations - Add cache statistics endpoint (GET /api/cache/stats) - Add cache management endpoint (DELETE /api/cache) - Cache hit rate tracking and monitoring - Pattern-based cache invalidation - Optimized for Raspberry Pi deployment (lightweight in-memory) 🤖 Generated with Claude Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ const {
|
||||
} = require("../middleware/validators/eventValidator");
|
||||
const { paginate, buildPaginatedResponse } = require("../middleware/pagination");
|
||||
const couchdbService = require("../services/couchdbService");
|
||||
const { getCacheMiddleware, invalidateCacheByPattern } = require("../middleware/cache");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -16,6 +17,7 @@ const router = express.Router();
|
||||
router.get(
|
||||
"/",
|
||||
paginate,
|
||||
getCacheMiddleware(120), // Cache for 2 minutes
|
||||
asyncHandler(async (req, res) => {
|
||||
const { page, limit } = req.pagination;
|
||||
|
||||
@@ -50,6 +52,9 @@ router.post(
|
||||
location,
|
||||
});
|
||||
|
||||
// Invalidate events cache
|
||||
invalidateCacheByPattern('/api/events');
|
||||
|
||||
res.json(event);
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user