mob
mob

Reputation: 118665

How do I read server data from a Catalyst::Plugin::Session::Store::File from another app?

I am running two applications on my server. The first is a Catalyst app, configured to use the Session / Session::State::Cookie / Session::Store::File suite of plugins to save some session state on the server side.

The other app is in Perl, but it's not Catalyst. I want the server-side session data from the Catalyst app to be available to the other app.

In the second app, I can load the client-side cookies and find the relevant session id for the Catalyst app, but after that I'm stuck. I don't know how to map the session id to a file name. For example, I have a session id de079f151917d184219ef357f5298d0da478e015, but the data for that session is only found in a file named fc1f6f651a2313c4081bcfef679061be35de40b7. How is the non-Catalyst app supposed to know how to find that file? (My follow up question would be how is the non-Catalyst app supposed to read that file, but I can cross that bridge when I get to it).

Is there an easier way to do this with a different storage scheme like Session::Store::DBIC or Session::Store::FastMmap?

Upvotes: 1

Views: 353

Answers (2)

hobbs
hobbs

Reputation: 240531

Session::Store::File uses Cache::FileCache. Simply instantiate a Cache::FileCache with a cache_root corresponding to where your app puts its session data, then use $cache->get("session:$sessid") to get the session data for a given $sessid, and if you need it, use $cache->get("expires:$sessid") to get the expiry time so that you can ignore a session if its expiration is before time().

Upvotes: 4

dgw
dgw

Reputation: 13666

If it is possible I would switch the session store to database, no need to search for files then.

Hope that helps.

Upvotes: 1

Related Questions