Re: [Cgi-session-user] writing CGI::Session sessions only when necessary
Brought to you by:
sherzodr
From: Mark S. <ma...@su...> - 2010-01-27 14:48:19
|
On Tue, 26 Jan 2010 16:42:38 -0800 Jonathan Swartz <SW...@PO...> wrote: > On our site we create a new CGI::Session object at the beginning of > the request, so that it can be used anywhere in the web code. > > However, sessions are rarely written to, so at the end of the request > I'd like to avoid actually writing out a new session to backing store > unless a param actually got set. The expense of writing out new > sessions, and cleaning them up later, has become significant. Jon, For a model of how to do this, see CGI::Application::Plugin::Session. I think you'll find the concepts there portable to your own code. Here's the overview: session_config() collects the necessary config details, but doesn't do anything with them. This runs on every request and just takes a momeent. session() lazy-loads a CGI::Session object using the details collected in session_config(). That is to say, the session is not loaded until you call a method on CGI::Session somewhere in your code like: $self->session->param('foo'); Many CGI::Application plugins are designed this way, often deferring loading even the helper modules themselves. This is one of the design principles that helps CGI::Application projects run well under CGI, because in a sense you only pay for what you use. Mark |