next-boost / next-boost

Add a cache layer for server-side-rendered pages with stale-while-revalidate. Can be considered as an implementation of next.js's Incremental Static Regeneration which works with getServerSideProps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cache should be deleted when a page hit 404

K3vinF opened this issue · comments

This looiks to be a regression from #3

When a page is no longer available after the page was cached, next-boost keeps serving it.
It is marked as 'stale', but the item is never removed from the cache.

I did some debugging in handler.js

If I add the following code

else { cache.del('payload:' + key) }

on line 97,. the item is correctly deleted.

So in context:

if (rv.statusCode === 200) { // save gzipped data const payload = { headers: rv.headers, body: (0, utils_1.isZipped)(rv.headers) ? body : (0, zlib_1.gzipSync)(body) }; yield cache.set('payload:' + key, (0, payload_1.encodePayload)(payload), ttl); } else { cache.del('payload:' + key) }

Steps to reproduce:

  • Visit a page;
  • Reload the page. Confirm it is server from next-boost cache;
  • Delete / unpublish the original page;
  • Reload the page again. It will be returned from next-boost;
  • Load the same page again, but with a query string to bypass next-boost (ie /page?no-cache);

The cached page will still load, but the uncached page shows a 404.