diff --git a/api/src/controllers/activity.ts b/api/src/controllers/activity.ts index 0da6f8335b..d56e424019 100644 --- a/api/src/controllers/activity.ts +++ b/api/src/controllers/activity.ts @@ -32,6 +32,7 @@ router.get( '/:pk', useCollection('directus_activity'), sanitizeQuery, + cacheMiddleware, asyncHandler(async (req, res) => { const service = new ActivityService({ accountability: req.accountability }); const record = await service.readByKey(req.params.pk, req.sanitizedQuery); diff --git a/api/src/controllers/collections.ts b/api/src/controllers/collections.ts index 000e8cf479..25b4a6e209 100644 --- a/api/src/controllers/collections.ts +++ b/api/src/controllers/collections.ts @@ -1,6 +1,7 @@ import { Router } from 'express'; import asyncHandler from 'express-async-handler'; import sanitizeQuery from '../middleware/sanitize-query'; +import cacheMiddleware from '../middleware/cache'; import CollectionsService from '../services/collections'; import useCollection from '../middleware/use-collection'; import MetaService from '../services/meta'; @@ -23,6 +24,7 @@ router.post( router.get( '/', useCollection('directus_collections'), + cacheMiddleware, asyncHandler(async (req, res) => { const collectionsService = new CollectionsService({ accountability: req.accountability }); const metaService = new MetaService({ accountability: req.accountability }); @@ -38,6 +40,7 @@ router.get( '/:collection', useCollection('directus_collections'), sanitizeQuery, + cacheMiddleware, asyncHandler(async (req, res) => { const collectionsService = new CollectionsService({ accountability: req.accountability }); const collectionKey = req.params.collection.includes(',') diff --git a/api/src/controllers/extensions.ts b/api/src/controllers/extensions.ts index 7a1946aace..ebbf1e606f 100644 --- a/api/src/controllers/extensions.ts +++ b/api/src/controllers/extensions.ts @@ -1,5 +1,6 @@ import { Router } from 'express'; import asyncHandler from 'express-async-handler'; +import cacheMiddleware from '../middleware/cache'; import * as ExtensionsService from '../services/extensions'; import { RouteNotFoundException } from '../exceptions'; @@ -7,6 +8,7 @@ const router = Router(); router.get( '/:type', + cacheMiddleware, asyncHandler(async (req, res) => { const typeAllowList = ['interfaces', 'layouts', 'displays', 'modules']; diff --git a/api/src/controllers/fields.ts b/api/src/controllers/fields.ts index 45d9880f88..bb856e0f64 100644 --- a/api/src/controllers/fields.ts +++ b/api/src/controllers/fields.ts @@ -2,6 +2,7 @@ import { Router } from 'express'; import asyncHandler from 'express-async-handler'; import FieldsService from '../services/fields'; import validateCollection from '../middleware/collection-exists'; +import cacheMiddleware from '../middleware/cache'; import { schemaInspector } from '../database'; import { FieldNotFoundException, InvalidPayloadException } from '../exceptions'; import Joi from 'joi'; @@ -20,6 +21,7 @@ const router = Router(); router.get( '/', useCollection('directus_fields'), + cacheMiddleware, asyncHandler(async (req, res) => { const service = new FieldsService({ accountability: req.accountability }); @@ -32,6 +34,7 @@ router.get( '/:collection', validateCollection, useCollection('directus_fields'), + cacheMiddleware, asyncHandler(async (req, res) => { const service = new FieldsService({ accountability: req.accountability }); diff --git a/api/src/middleware/cache.ts b/api/src/middleware/cache.ts index 3964027928..7372c539c3 100644 --- a/api/src/middleware/cache.ts +++ b/api/src/middleware/cache.ts @@ -20,6 +20,7 @@ const cacheMiddleware: RequestHandler = asyncHandler(async (req, res, next) => { // make the key of the cache the URL // need to check that this will work for all endpoints // node cache service + // have used query as then can decide whather to use cache or not from api call if (!req.query.TTL) return next(); if (!req.query.dTTL) return next();