mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add a cache clear method to the UtilsService (#19990)
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
5
.changeset/ten-icons-kiss.md
Normal file
5
.changeset/ten-icons-kiss.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@directus/api": minor
|
||||
---
|
||||
|
||||
Added `cacheClear` method to the `UtilsService`
|
||||
@@ -4,8 +4,7 @@ import { Router } from 'express';
|
||||
import Joi from 'joi';
|
||||
import fs from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import { flushCaches } from '../cache.js';
|
||||
import { ForbiddenError, InvalidPayloadError, InvalidQueryError, UnsupportedMediaTypeError } from '../errors/index.js';
|
||||
import { InvalidPayloadError, InvalidQueryError, UnsupportedMediaTypeError } from '../errors/index.js';
|
||||
import collectionExists from '../middleware/collection-exists.js';
|
||||
import { respond } from '../middleware/respond.js';
|
||||
import type { ImportWorkerData } from '../services/import-export/import-worker.js';
|
||||
@@ -194,11 +193,12 @@ router.post(
|
||||
router.post(
|
||||
'/cache/clear',
|
||||
asyncHandler(async (req, res) => {
|
||||
if (req.accountability?.admin !== true) {
|
||||
throw new ForbiddenError();
|
||||
}
|
||||
const service = new UtilsService({
|
||||
accountability: req.accountability,
|
||||
schema: req.schema,
|
||||
});
|
||||
|
||||
await flushCaches(true);
|
||||
await service.clearCache();
|
||||
|
||||
res.status(200).end();
|
||||
})
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { Accountability, SchemaOverview } from '@directus/types';
|
||||
import type { Knex } from 'knex';
|
||||
import { flushCaches, getCache } from '../cache.js';
|
||||
import getDatabase from '../database/index.js';
|
||||
import { systemCollectionRows } from '../database/system-data/collections/index.js';
|
||||
import emitter from '../emitter.js';
|
||||
import { ForbiddenError, InvalidPayloadError } from '../errors/index.js';
|
||||
import type { AbstractServiceOptions, PrimaryKey } from '../types/index.js';
|
||||
import { getCache } from '../cache.js';
|
||||
import { shouldClearCache } from '../utils/should-clear-cache.js';
|
||||
|
||||
export class UtilsService {
|
||||
@@ -147,4 +147,12 @@ export class UtilsService {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async clearCache(): Promise<void> {
|
||||
if (this.accountability?.admin !== true) {
|
||||
throw new ForbiddenError();
|
||||
}
|
||||
|
||||
return flushCaches(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,3 +79,4 @@
|
||||
- koredeycode
|
||||
- sajjadalis
|
||||
- Nihcep
|
||||
- nodeworks
|
||||
|
||||
Reference in New Issue
Block a user