Share Cache to another users

Hi, Hello I am new to here and what I trying to do is that when I type url with /values/data12 and I got respond data12 and cache this data12 in cache using caches.put, But when I try to make request from different browser and device, I don’t get response from cache, and after only refresh I got Cache, May be is it not possible to share Cache data to different users and am I wrong something?, Pls answer my question. ps. I am not using custom domain, I used with worker.dev.


import { Hono } from 'hono';
import { cors } from 'hono/cors';

const app = new Hono();

app.use('/*', cors());

// Function to cache the response
const cacheResponse = async (key: string, response: Response) => {
  const cache = caches.default;
  await cache.put(key, response.clone());
};

const getCachedResponse = async (key: string): Promise<Response | undefined> => {
  const cache = caches.default;
  const cachedResponse = await cache.match(key);
  return cachedResponse;
};

app.get('/values/:cacheKey', async (c) => {
  const cacheKey = c.req.param('cacheKey');

  const cacheUrl = new URL(c.req.url);

  cacheUrl.pathname = /values/${cacheKey};

  const cachedResponse = await getCachedResponse(cacheUrl.toString());
  if (cachedResponse) {
    const responseClone = new Response(cachedResponse.body, cachedResponse);
    responseClone.headers.set('Cache-Control', 'public, max-age=3600');
    const data = await responseClone.json();
    return c.json({ cache: data });
  }

  let data;
  try {
    data = JSON.parse(cacheKey);
  } catch (error) {
    data = { cacheKey };
  }

  const response = new Response(JSON.stringify({ result: data }), {
    headers: { 'Content-Type': 'application/json', 'Cache-Control': 'public, max-age=3600' },
  });

  await cacheResponse(cacheUrl.toString(), response);

  return response;
});

export default app;
This is my logic code

Hey there,

Unfortunately there isn’t currently a way to use what is cached for one account, with another Cloudflare account.

Thanks :slight_smile: