Problem with worker function and caching
# workers-help
i
I have recently setup a Cloudflare worker with a custom domain. I am trying to redirect users to specific domains based on the current path (domain/code),then by searching for that code in Upstash Redis. The issue I am facing is that even after updating the Redis key’s value, I keep getting redirected to the previously set value. I believe this is due to caching, but I am unable to figure out how to disable or bypass the caching. My worker function is: export default { async fetch(request, env) { return await handleRequest(request) } } async function handleRequest(request) { const url = new URL(request.url) const path = url.pathname const code = path.substring(1) const redirect_url = await get_url(code) return Response.redirect(redirect_url, 301) } async function get_url(code){ const response = await fetch(
https://upstash_redis.url
, { headers: { Authorization: "Bearer Token" } }) const data = await response.json() console.log(data) if(data.result != null ){ return data.result } else { return "https://www.example_deafult.com" } }
j
Can you share an example URL where this happens? I don’t see any caching in that code that could cause this. However, if you’re testing in a browser, browsers are very cache heavy when it comes to redirects. Try hitting it with
curl -I
or something
i
Yes, true. It turned out that my browser was caching the redirect data, as I was using 301 redirect. I changed it to 302 and it works now. Thank you very much for the help.