From 023755c56663942028a016a200ab2def104e67f5 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 18 May 2015 20:56:41 +0100 Subject: [PATCH] Cache invalidate for previews no issue - draft updates now need to affect the preview route --- core/server/api/index.js | 2 ++ core/server/middleware/index.js | 3 +++ core/test/functional/routes/api/posts_spec.js | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/server/api/index.js b/core/server/api/index.js index 1808b88817..9374dc7361 100644 --- a/core/server/api/index.js +++ b/core/server/api/index.js @@ -80,6 +80,8 @@ cacheInvalidationHeader = function (req, result) { // Don't set x-cache-invalidate header for drafts if (hasStatusChanged || wasDeleted || wasPublishedUpdated) { cacheInvalidate = '/*'; + } else { + cacheInvalidate = '/' + config.routeKeywords.preview + '/' + post.uuid + '/'; } } } diff --git a/core/server/middleware/index.js b/core/server/middleware/index.js index c2972d8e30..4a5df7c25a 100644 --- a/core/server/middleware/index.js +++ b/core/server/middleware/index.js @@ -301,8 +301,11 @@ setupMiddleware = function (blogAppInstance, adminApp) { blogApp.use(passport.initialize()); // ### Caching + // Blog frontend is cacheable blogApp.use(middleware.cacheControl('public')); + // Admin shouldn't be cached adminApp.use(middleware.cacheControl('private')); + // API shouldn't be cached blogApp.use(routes.apiBaseUri, middleware.cacheControl('private')); // enable authentication diff --git a/core/test/functional/routes/api/posts_spec.js b/core/test/functional/routes/api/posts_spec.js index 5ab803efbb..f88657dc7e 100644 --- a/core/test/functional/routes/api/posts_spec.js +++ b/core/test/functional/routes/api/posts_spec.js @@ -540,8 +540,8 @@ describe('Post API', function () { return done(err); } - // Updating a draft should not send x-cache-invalidate headers - should.not.exist(res.headers['x-cache-invalidate']); + // Updating a draft should send x-cache-invalidate headers for the preview only + res.headers['x-cache-invalidate'].should.eql('/p/' + draftPost.posts[0].uuid + '/'); done(); }); });