Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7904563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:08:05+00:00 2026-06-03T10:08:05+00:00

I have a question about the way view caching and browser caching work together

  • 0

I have a question about the way view caching and browser caching work together in CakePHP 2.1.

I’ve just upgraded my app to CakePHP 2.1, and set up HTTP caching using the new $this->response->modified method (which works well):

class ArticlesController extends AppController {
    public function view($id) {
        $article = $this->Article->find(
            'first',
            array('conditions' => array('Article.id' => $id))
        );

        $this->response->modified($article['Article']['modified']);

        $this->set(compact('article'));
    }
}

I have also set up CakePHP view caching:

class ArticlesController extends AppController {
    public $cacheAction = array(
        'view' => array('callbacks' => true, 'duration' => "1 week"),
    }
}

Both work well when used independently. However, when both are enabled, the CakePHP view caching seems to override the browser caching (specifically, no Last-Modified header is sent when pages are served from the CakePHP view cache). This stops the browser from caching pages that are being served from CakePHP’s view cache.

Ideally, I would like the browser to cache pages even if they are being served from CakePHP’s cache (i.e. I would like CakePHP to return a Last-Modified header, and respond to the browser’s If-Modified-Since request header, regardless of whether CakePHP has is returning a cached copy of page or not).

I’m just wondering whether this is expected behavior, whether I’m doing something wrong, or whether it’s something that has not been considered (or is not thought to be important).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:08:06+00:00Added an answer on June 3, 2026 at 10:08 am

    View caching, by nature, doesn’t actually execute the controller’s method on every request. I’m guessing it executes the action once and then caches the output to disk (or, whatever cache engine you happen to be using). If you look at the CacheHelper’s _writeFile method, you can see how the cached view is constructed.

        $file = '<!--cachetime:' . $cacheTime . '--><?php';
    
        if (empty($this->_View->plugin)) {
            $file .= "
            App::uses('{$this->_View->name}Controller', 'Controller');
            ";
        } else {
            $file .= "
            App::uses('{$this->_View->plugin}AppController', '{$this->_View->plugin}.Controller');
            App::uses('{$this->_View->name}Controller', '{$this->_View->plugin}.Controller');
            ";
        }
    
        $file .= '
                $request = unserialize(\'' . str_replace("'", "\\'", serialize($this->request)) . '\');
                $response = new CakeResponse(array("charset" => Configure::read("App.encoding")));
                $controller = new ' . $this->_View->name . 'Controller($request, $response);
                $controller->plugin = $this->plugin = \'' . $this->_View->plugin . '\';
                $controller->helpers = $this->helpers = unserialize(base64_decode(\'' . base64_encode(serialize($this->_View->helpers)) . '\'));
                $controller->layout = $this->layout = \'' . $this->_View->layout . '\';
                $controller->theme = $this->theme = \'' . $this->_View->theme . '\';
                $controller->viewVars = unserialize(base64_decode(\'' . base64_encode(serialize($this->_View->viewVars)) . '\'));
                Router::setRequestInfo($controller->request);
                $this->request = $request;';
    
        if ($useCallbacks == true) {
            $file .= '
                $controller->constructClasses();
                $controller->startupProcess();';
        }
    
        $file .= '
                $this->viewVars = $controller->viewVars;
                $this->loadHelpers();
                extract($this->viewVars, EXTR_SKIP);
        ?>';
    

    It creates a new Controller object (with a new CakeResponse) and loads all the helpers, plugins, etc that may be used in the view and writes it to cache.

    It appears that adding the Last-Modified header to the response of a cache action/view might require some deep modifications to the core CakePHP library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a general question about the way that database indexing works, particularly in
I have a question about whether or not a specific way of applying of
I have a question about the proper, best way to manage the model. I
I have a question about list in tcl, what is the correct way to
I am working on a card game iPhone app and have a question about
Quick question about CI. I have a view with a form, several text input
I have a question about presenting the TWTweetComposerViewController as a modal view in iOS
I have a question about the architecture of a backbone.js web app. Let's say
A question about didReceiveMemoryWarning / viewDidUnload . If my app has many view controllers,
I have a question about mirroring and cross-db views. We have a view in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.