Caching a proxied request always misses cache

I’m trying to serve a third party script but proxy it through my site’s domain. Even after following the cookbook guide, I’m still seeing every request miss the cache.

Here’s my layer0.config.js:

module.exports = {
  connector: '@layer0/next',
  prerenderConcurrency: 1,
  backends: {
    plausible: {
      domainOrIp: 'plausible.io',
      hostHeader: 'plausible.io',
    },
  },
};

And routes.js:

.match('/js/measure.js', ({ cache, proxy }) => {
    cache({
      edge: {
        maxAgeSeconds: 60 * 60 * 24 * 365,
        staleWhileRevalidateSeconds: 60 * 60,
      },
    });
    proxy('plausible', { path: '/js/plausible.js' });
  })

Running curl (curl -o/dev/null -vv https://calmernews-calmernews-default.layer0.link/js/measure.js) shows a cache miss in the server timing header, and x-0-t shows oc=pass. I tried switching to .get() instead of .match() and also renamed the file/removed the path option but didn’t see any change. Is there something else I’m missing in my router?

It looks like your upstream has cache-control: private in the response header, which will cause the cache to be skipped unless you specifically force it with forcePrivateCaching: true.

https://docs.layer0.co/guides/caching#section_private

➜  ~ scurln https://plausible.io/js/plausible.js
HTTP/2 200
access-control-allow-origin: *
cache-control: max-age=0, private, must-revalidate
content-length: 1350
content-type: application/javascript
cross-origin-resource-policy: cross-origin
date: Mon, 19 Jul 2021 14:42:05 GMT
server: Netlify
age: 0
x-nf-request-id: 01FAZKF27HA9SDYBY5DH1RVWKW


Status: 200, Connect: 0.194143, TTFB: 0.701568, Total: 0.740743%