Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I stop iCal from caching my PHP-generated iCalendar feed?

I made a dynamically generated iCalendar feed with PHP, sticking to RFC 5545. It's working just fine for the most part, except iCal (i.e. Mac OS X's built-in calendar program) seems to refuse to reflect updates to events it had previously already downloaded. I'm assuming this is due to caching. Is there a way I can tell iCal not to cache my feed?

EDIT: Oh yeah, I forgot to mention that I've already tried making each VEVENT have a different UID each time the feed is called (my UID format is "id", where is the current time in RFC 5545's DATE-TIME format, and is the unique ID of the event in my database). I've also tried playing with the Content-type in the header; this problem happens whether I set it to text/plain or text/calendar

like image 502
Hayden Schiff Avatar asked Oct 08 '22 20:10

Hayden Schiff


2 Answers

I've never dealt with iCal but try setting the headers to force revalidation.

<?php
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
like image 165
Crashspeeder Avatar answered Oct 13 '22 10:10

Crashspeeder


Have you tried adding "no-cache" headers?

<?php
header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); //date in the past
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); //tell it we just updated
header( 'Cache-Control: no-store, no-cache, must-revalidate' ); //force revaidation
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' ); 
?>
like image 42
Ben D Avatar answered Oct 13 '22 10:10

Ben D