McGuireR
McGuireR
CDCloudflare Developers
Created by McGuireR on 4/29/2025 in #general-help
Problem with cache API in worker.
I'm having problems with the cache API in my worker.
High-level setup: I have a single website, let's call it mcguirer.com, with some pages served by a NextJS Pages app (let's say it's at mcguirer.pages.dev), which retrieves page content from a headless CMS.
The mcguirer.com URLs that are served by the pages app, are routed to a worker (mcguirer-worker) that changes the URLs from, for example, https://mcguirer.com/blog/april2025 to https://mcguirer.pages.dev/blog/april2025. The worker then does the fetch() and returns the response. Any URL that is not a worker route for that worker is routed directly to the origin server. My problem is with getting the pages served by the worker to be cached. I've tried multiple versions of worker code using the cache API, both a the match() and put() idiom and the fetch() idiom, and none of them seem to do that right thing; - https://developers.cloudflare.com/workers/runtime-apis/cache/ - https://developers.cloudflare.com/workers/examples/cache-using-fetch/ In both cases, the cache seems to be ignored. If I start with an empty cache, load a page that's routed through the worker, make a change to the page content in the CMS, clear my browser cache, and reload the page, I get the new version of the page. I would expect the old version of the page to be served from cache for the cache TTL of four hours. I also a cache rule with a trigger condition of http.host eq "mcguirer.com" and an action of "Eligible for cache" and "Ignore cache-control header and use this TTL - 4 hours". However, I'm getting the same worker behavior regardless of whether I have the Cache Rule enabled or not. BTW, yes, I tried searching for previous messages about this issue. I found a few, but the proposed solutions didn't work. I'm going to continue searching back through the history here.
6 replies
CDCloudflare Developers
Created by McGuireR on 3/7/2024 in #general-help
Multiple URL Rewrite rules aren't triggering.
I have a site with multiple URL Rewrite Transform rules. One of them rewrite the path. Then a subsequent rule should trigger on that rewritten rule and make a different change. However, when I run a trace, I only see the first rule triggering but not the second. e.g. Rule 1: Rewrite Banana to Mango (http.host eq "example.com" and http.request.uri.path eq "/banana") Path: Rewrite to Static /mango Rule 2: Rewrite Mango to Homepage (http.host eq "example.com" and http.request.uri.path eq "/mango") Path: Rewrite to Static / When I go to example.com/mango in a browser (triggering only rule 2), I do indeed get the home page served. However, when I go to example.com/banana, it gets rewritten to /mango but does NOT subsequently get rewritten to /. Because /mango isn't a real page, I get a 404. From https://developers.cloudflare.com/rules/transform/:
Transform Rules run in order. Rules that appear later in the list of Transform Rules can overwrite changes done by previous rules. You can define the rule order in the dashboard or via API.
Shouldn't the second URL Rewrite rule be able to trigger on a URL that was modified by an earlier rule?
2 replies