0
Answered

Can't get cache control headers to work

HebcalUser25 2 years ago updated 2 years ago 4

Hi all,

First of all thanks for this great API!!

I'm working on an application that sends out a request everyday to update the Jewish holidays on a calender. However I've noticed now 2 days in a row that it's using old data, even when I create a new request. I use this request:

https://www.hebcal.com/shabbat?cfg=json&b=18 (and a private geonameid)

I've put now cache control headers in my request with: cache-control: no-cache, or cache-control: no-cache, max-age=0. I've been playing around with the headers a little bit, but they all still result in receiving data from 2 days old. I know I can specify the date in the API request (or a HTTP header), but I'm using a simple device that doesn't know its current time and date and would make things pretty complicated, thus I was hoping anyone could help me out on how to properly get always fresh data!

I'm not sure whether I'm doing something wrong here, or if it's on the server side. The API docs: https://www.hebcal.com/home/197/shabbat-times-rest-api says it is able to handle cache-control.

Thanks for any help!

Answer

Answer
Answered

OK, we have modified the server configuration to respect Cache-Control: no-cache. The change is live in production.

Just to reiterate the point made earlier: given the design of the Shabbat API, your application should not need to send that header in order to operate correctly. The Shabbat API is designed to serve the current week's results through Sunday at midnight in the timezone of the city specified by the geonameid parameter. The Expires header is set explicitly so our caching servers reduce load on our app servers while preserving full functionality for clients like yours.

You can, of course, feel free to send the header, and it will now do as you expect: it will bypass our caching layer and force our app server to recalculate the current week's Shabbat info.

Under review

Hi, thanks for using Hebcal.

The short answer is that yes, you're receiving data that's 2 days old, but is still 100% correct with respect to what the Shabbat API is trying to do. Here are the headers we see when requesting that URL.

HTTP/2 200 
server: nginx/1.18.0 (Ubuntu)
date: Tue, 30 Aug 2022 16:45:32 GMT
content-type: application/json; charset=utf-8
content-length: 2447
vary: Accept-Encoding
etag: W/"1c9-JWtHF6a7KHzEBkekWL2HWbypsK0"
last-modified: Sun, 28 Aug 2022 09:46:10 GMT
expires: Sat, 03 Sep 2022 22:00:00 GMT
x-response-time: 3.829ms
x-varnish: 83568151 65035843
age: 197961
via: 1.1 varnish (Varnish/6.6)
access-control-allow-origin: *
accept-ranges: bytes

This is actually what we expect to see. The content is valid until 

Sat, 03 Sep 2022 22:00:00 GMT

Which is midnight Sunday in your timezone.

The longer answer is that our server config isn't respecting Cache-control: no-cache and we should fix that.

Hi Michael, thanks for your reply! That makes sense.

"The longer answer is that our server config isn't respecting Cache-control: no-cache and we should fix that."

I hope I'm not rude asking, since this is a great API and possibly maintainted in your free time, but will it really be fixed too? Or only maybe later on in development? :)

Thanks for any help once again.

    Answer
    Answered

    OK, we have modified the server configuration to respect Cache-Control: no-cache. The change is live in production.

    Just to reiterate the point made earlier: given the design of the Shabbat API, your application should not need to send that header in order to operate correctly. The Shabbat API is designed to serve the current week's results through Sunday at midnight in the timezone of the city specified by the geonameid parameter. The Expires header is set explicitly so our caching servers reduce load on our app servers while preserving full functionality for clients like yours.

    You can, of course, feel free to send the header, and it will now do as you expect: it will bypass our caching layer and force our app server to recalculate the current week's Shabbat info.

    Thanks a lot!! I see what you mean indeed.

    Since I am programming this application on a microcontroller I find it difficult to extract certain JSON data and make HTTP requests, I'm using C/C++. If it were for Python I think I would have been able to implement that logic, to skip the previous dates in the JSON data and only use the ones for the future.

    However, since I plan to only send a request once a day (now for testing maybe a little more), I hope to not put that much load on the servers and use the cache-control: no-cache as my solution for now :). 

    Thanks once again.