0
votes

I have an app that uses CakeSession for saving different user data. Now I want to write some default values using CakeSession::write() and have them available for all views (also for cached views). So the check/write should be done on every request before the view is rendered.

But where to put the code to match these requirements? Until now, I tried the following positions to use CakeSession::write() but without success:

  1. Config/bootstrap.php -> CakeSession is not defined yet
  2. AppController::__construct() -> CakeSession is not defined yet
  3. AppController::beforeFilter() -> will not be called for cached views
1
you can pass 'callbacks'=>true as a param of cacheAction which fires the beforeFilter. - Ross
@Ross Thank you for this info. I think this is a possible solution. Can you say something about the performance for cached files when callbacks are fired? - mixable
you'd have to do your own benchmarking, too many factors involved. And this sounds a bit like premature optimization - be aware, but wait until it becomes a problem before worrying too much. - Ross
I was just asking because I was expecting a much higher impact on the performance. But everything works like a charm. Thanks! - mixable

1 Answers

0
votes

Nowhere will cached views create sessions. A cached view does not initialise a request at all

docs

It should be noted that once an action is cached, the controller method for the 
action will not be called. When a cache file is created, the request object, 
and view variables are serialized with PHP’s serialize().