Welcome Guest, Not a member yet? Register   Sign In
Cache-Control header always prepend "no-store, no-cache, must-revalidate"
#7

(03-01-2024, 06:32 AM)bgeneto Wrote: 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.

I do it in the `app\Config\Events.php` file:

PHP Code:
Events::on('pre_system', static function () {

    /*
    * --------------------------------------------------------------------
    * Session start
    * --------------------------------------------------------------------
    * We start the session here and not in the controller, so it is also available in the models/libraries...
    * which may be executed before the controller is initiated.
    * Under CLI, session halts itself so no need to have it.
    * See: https://codeigniter.com/user_guide/libraries/sessions.html
    */
    if (! is_cli()) {
        // When the session starts, PHP executes implicitely `session_cache_limiter('nocache')`
        // See: https://www.php.net/manual/en/function.session-cache-limiter
        // We prevent PHP from sending headers by using `session_cache_limiter('')`
        session_cache_limiter('');
        // Start the session (no need for `Services::session()->start()`)
        Services::session(); // or: service('session')
    }

Reply


Messages In This Thread
RE: Cache-Control header always prepend "no-store, no-cache, must-revalidate" - by parisiam - 03-01-2024, 10:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB