Re: [Cgi-session-user] writing CGI::Session sessions only when necessary
Brought to you by:
sherzodr
From: Jonathan S. <sw...@po...> - 2010-01-27 15:27:51
|
On Jan 27, 2010, at 6:41 AM, Mark Stosberg wrote: > 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. > Thanks Mark. I thought of this idea too. But will this end up creating a session if someone simply *reads* a session parameter? I'd like to only create the session if someone actually *writes* a session parameter. The latter will occur far less often. |