CodeIgniter Forums
Caching and headers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Caching and headers (/thread-9872.html)

Pages: 1 2 3 4 5 6 7 8 9 10


Caching and headers - El Forum - 07-10-2008

[eluser]Aquillyne[/eluser]
I'm having a little problem.

I want to enable caching for a page, but I want the cached data to be sent with a header(). It seems like when there's a cache CI completely skips the Controller and just delivers. Is there any way to force CI to run some code before delivering the cache (for just this page)?

To put this in perspective: I have a controller/view that outputs CSS to the browser. I want that CSS cached so it isn't generated every time. But I also must send the "text/css" mimetype header, or it won't work.

Any suggestions?

Thanks.


Caching and headers - El Forum - 07-11-2008

[eluser]Seppo[/eluser]
I believe that if you send the header trhough the output class ($this->output->set_header) it will also be cached and delivered the next time... but I hadn't use it, so I'm not sre


Caching and headers - El Forum - 07-11-2008

[eluser]Aquillyne[/eluser]
[quote author="Seppo" date="1215792983"]I believe that if you send the header trhough the output class ($this->output->set_header) it will also be cached and delivered the next time... but I hadn't use it, so I'm not sre[/quote]

Unfortunately this doesn't work!

The cache, it seems, only stores the bare content of the page, and no headers that were sent with it.

Is there any way to send a header with the cache?


Caching and headers - El Forum - 07-11-2008

[eluser]Seppo[/eluser]
Shit... That would be a nice feature...
A temp solution would be using a cache_override hook... but I'm not sure how can you realize if the cache is a css or not...


Caching and headers - El Forum - 07-11-2008

[eluser]Aquillyne[/eluser]
[quote author="Seppo" date="1215815668"]Shit... That would be a nice feature...
A temp solution would be using a cache_override hook... but I'm not sure how can you realize if the cache is a css or not...[/quote]

I agree. I thought of using a hook, but doesn't that mean I basically override the CI cache logic with my own? That's something I don't want to do as I rather like the way CI handles it right now, it just needs a bit extra.

Perhaps if I extend the output class somehow?

As I said, all I want to do is send a header with the cache - there must be a loophole in there somewhere!


Caching and headers - El Forum - 07-11-2008

[eluser]beemr[/eluser]
I've got just the solution for you. Josh Surber wrote up a patch that would retain cache headers, but like you I'm not interested in forking the code. Turns out that all I needed to do is extract the changes into Output and URI extensions and voila! Suffix cache


Caching and headers - El Forum - 07-11-2008

[eluser]Aquillyne[/eluser]
[quote author="beemr" date="1215828529"]I've got just the solution for you. Josh Surber wrote up a patch that would retain cache headers, but like you I'm not interested in forking the code. Turns out that all I needed to do is extract the changes into Output and URI extensions and voila! Suffix cache[/quote]

I'm not a fan of using code I don't understand. What are these extensions exactly doing? I can't see how all of it is required just to send headers. I really don't need the suffix functionality.

Ideally I'd like to extend nothing more than the $this->output->set_header() function so that it stores that header information in a cache, and then somehow call that again. Isn't there a slimmer way of doing this with just, perhaps, the pre-cache hook?


Caching and headers - El Forum - 07-11-2008

[eluser]Aquillyne[/eluser]
In general it would really help if someone could explain exactly how CI handles caching at the moment, because I'm lost on it. How, for instance, does it store the time at which a cache ought to expire? (Surely if this information is stored somewhere, headers could be stored in a similar way).


Caching and headers - El Forum - 07-12-2008

[eluser]Seppo[/eluser]
Well... the solution to the expire time in CI is not really nice.... CI writes a file preppending the expiration timestamp and "TS--->" to the output... very ugly, if I may...


Caching and headers - El Forum - 07-12-2008

[eluser]beemr[/eluser]
The cache files used by CI contain the final text output from a previous execution of a controller. CI only adds a timestamp to the beginning of that text file but no header info is stored. The name for the text file is the MD5-encrypted URL for the controller. To maximize its efficiency, CI calls for the cache file as early in the request as possible so there are only a few classes loaded and available. Essential to this are the URI and Output classes. CI has to MD5 the URI in order to find the cache file. Then Output regex's out the timestamp to check whether or not the file is expired.

Suffix cache just goes the extra mile and adds headers to the cache file and a suffix to the URI that gets MD5'ed into a the cache file's name. If the suffix wasn't stored as part of the lookup name, you would end up overwriting your controller's cache with the cache of its css or js. That means that Josh needed to extend URI to add the suffix and then extend Output to parse out the headers from the text file.