Cache Images from BackBlaze B2

#1

How can I get images from BackBlaze B2 to be cached on CloudFlare?

What I have done so far is:

  1. Create a new CNAME with name ‘cdn’ and value ‘https://f000.backblazeb2.com

After doing this, I can access a file like https://f000.backblazeb2.com/file/myBucket/myFile.png as https://cdn.myDomain.com/file/myBucket/myFile.png

  1. I created a new Page Rule: https://cdn.myDomain.com/file/myBucket/* with ‘Cache Level’ set to ‘Cache Everything’

  2. I followed the instructions from here to see if my image is cached: https://support.cloudflare.com/hc/en-us/articles/200169556-How-can-I-tell-if-Cloudflare-is-caching-my-site-or-a-specific-file-

I ran the test from https://www.webpagetest.org from the same location multiple times so the image should be cached, but each time I check I see: cf-cache-status: MISS

Does anything come to mind for why this isn’t working?

Thanks for your help.

#2

Your configuration generally looks all right, however the origin might send some caching headers which could effectively disable the edge cache.

Can you post an actual URL?

#4

Your server appears to send

Cache-Control: max-age=0, no-cache, no-store

Can you remove that directive?

#5

Sorry, I’m not sure where I can change that. Would that be some setting in CloudFlare or in BackBlaze?

#6

On your origin.

Should that not be possible, maybe try tinkering with these directives in your page rule

image

1 Like
#7

Thank you very much for your help. I was able to successfully get caching using either of your suggested methods and see ‘cf-cache-status: HIT’ for both methods.

  1. Headers in BackBlaze are set at the bucket level. If you go to the ‘Bucket Settings’ and set ‘Bucket Info’ to {“cache-control”:“max-age=7200”} then it sets the appropriate headers for 2 hours. Note that regardless of what value I set for max-age, I still see ‘cache-control: public, max-age=14400’ when I test it on https://www.webpagetest.org.

  2. To change it in CloudFlare, you just need a page rule for Edge Cache TTL which overrides the cache expiry in the headers. Since I was only interested in caching images, I didn’t need the ‘Cache Everything’ rule. Using this method I can set the TTL to as low as 2 hours (on the free plan) as opposed to 4 hours (by changing the headers directly in the BackBlaze bucket).

closed #8

This topic was automatically closed after 30 days. New replies are no longer allowed.