I understand that workers are billed per invocation, but I want to create a system that returns fairly static data as cheap as possible.
If I have a worker at site.com/api/getdata?id=abc123
can I set it up so that the worker gets the data from the database and returns it with a cache header like s-maxage=31536000
. With this cache header will all subsequent requests to the worker be cached by cloudflare and NOT invoke/bill for a worker request for the next 1 year (side note: in the workers plans are cache hits free?)
The data will change infrequently, but not at a set rate (like the 1 year TTL), so if my assumption above about the cache is correct, to further enhance the system, when I make a change in my backend can I then use the cache API to purge the cache specifically for the ID that was changed and now the next request WILL invoke the worker again, get the updated data and cache it for another year (or until I purge it again via api).
Background, I need to serve ~1-2kb json files to millions of hits/end users as cheap as possible (not in theory, this is for a live system) and when the data is changed it has to reflect to the end users right away, but I don't want to invoke millions of worker invocations (or run millions of requests on an actual server if I didn't use workers).