Plugin::Session lazy start

I have an application that uses sessions with a FastMmap store. This application also includes a custom script (using Catalyst::ScriptRole) used to perform certain administrative tasks from the command line.

The problem is that Catalyst tries to unlink and recreate the session cache every time it starts (somewhere in the bowels of MyApp->setup(), I imagine). This is obviously a bad idea if the application is running, but it is a problem even if the application isn't running if the session cache is owned by a different user (e.g. www) than the one that runs the script (e.g. des).

Is there a way to have C::Plugin::Session (or C::P::S::Store::FastMmap) initialize the cache on first use instead of at startup?

As an alternate solution, is there a way to have it use a different file name every time it starts?

Will Crawford <billcrawford1970 [at] gmail> writes: > Dag-Erling Smørgrav <des [at] des> writes: > > Is there a way to have C::Plugin::Session (or C::P::S::Store::FastMmap) > > initialize the cache on first use instead of at startup? > { ..., unlink_on_exit => 0 } in your config.

"delete the cache when you're done" is very different from "don't create the cache until you actually need it".

> > As an alternate solution, is there a way to have it use a different file > > name every time it starts? > Personally I go with having a relative path in the myapp_local.conf > that puts them all in a tmp/ subdirectory of where I'm running the > server, then an absolute path in myapp.conf for the real thing.

The script runs with the exact same configuration as the application, including myapp_local.conf. That's the whole point of using a Catalyst script instead of a standalone program.

Ashley Pond V <apv [at] sedition> writes: > Dag-Erling Smørgrav <des [at] des> writes: > > As an alternate solution, is there a way to have it use a different file > > name every time it starts? > Here's a snippet to do that: [...]

*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien Handelsgericht Wien, FN 79340b *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* Notice: This e-mail contains information that is confidential and may be privileged. If you are not the intended recipient, please notify the sender and then delete this e-mail immediately. *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

I was wrong about that last bit - unlink_on_exit automatically defaults to a sane value (unlink the file if you created it, leave it alone if it already existed). If anything, you'd want to set it to 0 so sessions are persistent across server restarts.

BTW, this is not a perfect solution, since all processes owned by the same user will now share a session cache. However, this should rarely (if ever) be a problem.