![]() |
Cache-Control header always prepend "no-store, no-cache, must-revalidate" - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Cache-Control header always prepend "no-store, no-cache, must-revalidate" (/showthread.php?tid=88325) |
Cache-Control header always prepend "no-store, no-cache, must-revalidate" - parisiam - 08-22-2023 I'm using PHP 8.1 and CI 4.3.7 I've built a filter to change HTTP caching (Cache-Control header) for some pages of my website. PHP Code: class CacheFilter implements FilterInterface I apply the filter (alias is 'cache') to the routes : PHP Code: $routes->get('page', 'PageController::view', ['filter' => 'cache']); I always end up with this values for Cache-Control in the response header: Code: Cache-Control: no-store, no-cache, must-revalidate, public, max-age=3600, s-maxage=86400 The expected response is: Code: Cache-Control: public, max-age=3600, s-maxage=86400 I tried several browsers with the same result. I tried to follow CI code up to codeigniter.php and everything seems right. So what's the problem ? Anyone has ever seen this ? RE: Cache-Control header always prepend "no-store, no-cache, must-revalidate" - sammyskills - 08-22-2023 Please create an issue: https://github.com/codeigniter4/CodeIgniter4/issues RE: Cache-Control header always prepend "no-store, no-cache, must-revalidate" - ozornick - 08-22-2023 Session init in files? See session_cache_limiter() Turn off RE: Cache-Control header always prepend "no-store, no-cache, must-revalidate" - kenjis - 08-22-2023 It is already reported: https://github.com/codeigniter4/CodeIgniter4/issues/7266 RE: Cache-Control header always prepend "no-store, no-cache, must-revalidate" - parisiam - 08-22-2023 (08-22-2023, 08:10 AM)ozornick Wrote: Session init in files? See session_cache_limiter() Turn off Yes you're totally right ! Thank you very much for your hint ![]() It led me to the solution I found. I'll develop it in my answer to Kenjis (08-22-2023, 01:48 PM)kenjis Wrote: It is already reported: Sorry, I didn't check for the issues before posting my message. I think I found the origin of the problem thanks to ozornick and a solution (that I implemented already, it works). When using sessions (when the session starts), PHP automatically sends Cache-Control instruction to the header (see my initial post). It implicitely execute this instruction: PHP Code: session_cache_limiter('nocache'); The problem is that the headers sent by session_cache_limiter() cannot be replaced or removed by CodeIgniter methods and functions such as: PHP Code: // removeHeader() does NOT remove the headers sent by session_cache_limiter() The solution is to stop theses headers from being issued BEFORE the session starts by using `session_cache_limiter('');`: PHP Code: // We prevent PHP from sending the cache related headers That's it. It's not really a bug of CodeIgniter, simply (for my part) the ignorance that when starting a session, PHP would send Cache related headers. Thanks for your help. RE: Cache-Control header always prepend "no-store, no-cache, must-revalidate" - bgeneto - 03-01-2024 (08-22-2023, 03:00 PM)parisiam Wrote: The solution is to stop theses headers from being issued BEFORE the session starts by using `session_cache_limiter('');`:Ok, and where in your code do you put the `session_cache_limiter('')` in order to avoid the error below? Code: session_cache_limiter(): Session cache limiter cannot be changed when a session is active I've tried in the initController method of my BaseController class without success. What is the official CI4 solution for this header duplication issue? Is there any way to take control of the Cache-Control header while using sessions in CI4? TIA. RE: Cache-Control header always prepend "no-store, no-cache, must-revalidate" - parisiam - 03-01-2024 (03-01-2024, 06:32 AM)bgeneto Wrote: I've tried in the initController method of my BaseController class without success. I do it in the `app\Config\Events.php` file: PHP Code: Events::on('pre_system', static function () { RE: Cache-Control header always prepend "no-store, no-cache, must-revalidate" - ozornick - 03-01-2024 I write code in app/Common.php Before init CI RE: Cache-Control header always prepend "no-store, no-cache, must-revalidate" - kenjis - 03-09-2024 The bug will be fixed in v4.4.7. https://github.com/codeigniter4/CodeIgniter4/pull/8601 |