mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add new /utils/cache/clear endpoint (#7014)
This commit is contained in:
@@ -2,12 +2,13 @@ import argon2 from 'argon2';
|
||||
import { Router } from 'express';
|
||||
import Joi from 'joi';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { InvalidPayloadException, InvalidQueryException } from '../exceptions';
|
||||
import { ForbiddenException, InvalidPayloadException, InvalidQueryException } from '../exceptions';
|
||||
import collectionExists from '../middleware/collection-exists';
|
||||
import { respond } from '../middleware/respond';
|
||||
import { RevisionsService, UtilsService, ImportService } from '../services';
|
||||
import asyncHandler from '../utils/async-handler';
|
||||
import Busboy from 'busboy';
|
||||
import { getCache } from '../cache';
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -115,4 +116,20 @@ router.post(
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/cache/clear',
|
||||
asyncHandler(async (req, res) => {
|
||||
if (req.accountability?.admin !== true) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
const { cache, schemaCache } = getCache();
|
||||
|
||||
await cache?.clear();
|
||||
await schemaCache?.clear();
|
||||
|
||||
res.status(200).end();
|
||||
})
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -44,9 +44,10 @@ import {
|
||||
import { Knex } from 'knex';
|
||||
import { flatten, get, mapKeys, merge, set, uniq } from 'lodash';
|
||||
import ms from 'ms';
|
||||
import { getCache } from '../cache';
|
||||
import getDatabase from '../database';
|
||||
import env from '../env';
|
||||
import { BaseException, GraphQLValidationException, InvalidPayloadException } from '../exceptions';
|
||||
import { BaseException, ForbiddenException, GraphQLValidationException, InvalidPayloadException } from '../exceptions';
|
||||
import { listExtensions } from '../extensions';
|
||||
import { AbstractServiceOptions, Accountability, Action, GraphQLParams, Item, Query, SchemaOverview } from '../types';
|
||||
import { getGraphQLType } from '../utils/get-graphql-type';
|
||||
@@ -1609,6 +1610,21 @@ export class GraphQLService {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
utils_cache_clear: {
|
||||
type: GraphQLVoid,
|
||||
resolve: async () => {
|
||||
if (this.accountability?.admin !== true) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
const { cache, schemaCache } = getCache();
|
||||
|
||||
await cache?.clear();
|
||||
await schemaCache?.clear();
|
||||
|
||||
return;
|
||||
},
|
||||
},
|
||||
users_invite_accept: {
|
||||
type: GraphQLBoolean,
|
||||
args: {
|
||||
|
||||
@@ -269,3 +269,38 @@ n/a
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
## Clear the Internal Cache
|
||||
|
||||
Resets both the data and schema cache of Directus. This endpoint is only available to admin users.
|
||||
|
||||
<div class="two-up">
|
||||
<div class="left">
|
||||
|
||||
### Request Body
|
||||
|
||||
n/a
|
||||
|
||||
### Returns
|
||||
|
||||
Empty body
|
||||
|
||||
</div>
|
||||
<div class="right">
|
||||
|
||||
### REST API
|
||||
|
||||
```
|
||||
POST /utils/cache/clear
|
||||
```
|
||||
|
||||
### GraphQL
|
||||
|
||||
```graphql
|
||||
mutation {
|
||||
utils_cache_clear
|
||||
}
|
||||
```
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user