Skip to content

Commit 4e17463

Browse files
committed
Dang need it for tests
1 parent 750f518 commit 4e17463

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

cache/middleware.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,21 @@ const cacheStats = (req, res) => {
453453
res.status(200).json(response)
454454
}
455455

456+
/**
457+
* Middleware to clear cache at /cache/clear endpoint
458+
* Should be protected in production
459+
*/
460+
const cacheClear = (req, res) => {
461+
const sizeBefore = cache.cache.size
462+
cache.clear()
463+
464+
res.status(200).json({
465+
message: 'Cache cleared',
466+
entriesCleared: sizeBefore,
467+
currentSize: cache.cache.size
468+
})
469+
}
470+
456471
/**
457472
* Cache middleware for GOG fragments endpoint
458473
* Caches POST requests for WitnessFragment entities from ManuscriptWitness
@@ -551,5 +566,6 @@ export {
551566
cacheGogFragments,
552567
cacheGogGlosses,
553568
invalidateCache,
554-
cacheStats
569+
cacheStats,
570+
cacheClear
555571
}

routes/api-routes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import sinceRouter from './since.js';
4545
// Support GET requests like v1/history/{object id} to discover all previous versions tracing back to the prime.
4646
import historyRouter from './history.js';
4747
// Cache management endpoints
48-
import { cacheStats } from '../cache/middleware.js'
48+
import { cacheStats, cacheClear } from '../cache/middleware.js'
4949

5050
router.use(staticRouter)
5151
router.use('/id',idRouter)
@@ -64,6 +64,7 @@ router.use('/api/unset', unsetRouter)
6464
router.use('/api/release', releaseRouter)
6565
// Cache management endpoints
6666
router.get('/api/cache/stats', cacheStats)
67+
router.post('/api/cache/clear', cacheClear)
6768
// Set default API response
6869
router.get('/api', (req, res) => {
6970
res.json({

0 commit comments

Comments
 (0)