md wrote:

>I don't think "global" was the term I should have
>used. What I mean is data that will be seen on all or
>most pages by the same user...like "Hello Jim"
>

Okay, don't put that in the session.  It belongs in a cache.  The 
session is for transient state information, that you don't want to keep 
after the user logs out.

>Current page name and id are never stored in db, so
>different browser windows can be on different
>pages...
>

I thought your session was all stored in MySQL.  Why are you putting 
these in the session exactly?  If these things are not relevant to more 
than one request (page), they don't belong in the session.  They should 
just be in ordinary variables.

>>That sounds like a "user" or "subscriptions" object
>>to me, not session data.
>>    
>>
>
>Once again, I shouldn't have used the term "global".
>This is the "subscriptions" info for a single
>user...that's why I had thought to put this in the
>session instead of pulling from the db each page call
>since the data will rarely change.
>

You should use a cache for that, rather than the session.  This is 
long-term data that you just want quicker access to.

>I am using TT caching
>for the templates, but I'm not sure how to cache the
>non-session data.
>

Template Toolkit caches the compiled template code, but it doesn't cache 
your data or the output of the templates.  What you should do is grab a 
module like Cache::Cache or Cache::Mmap and take a look at the examples 
there.  You use it in a way that's very similar to what you're doing 
with Apache::Session for the things you referred to as global.  There 
are also good examples in the documentation for the Memoize module.

There are various reasons to use a cache rather than treating the 
session like a cache.  If you put a lot of data in the session, it will 
slow down every hit loading and saving that data.  In a cache, you can 
just keep multiple cached items separately and only grab them if you 
need them for this page.  With a cache you can store things that come 
from the database but are not user-specific, like today's weather.

>What about something like "default page id", which is
>the page that is considered your home page? This id is
>stored permanently in the db ("lasts more than the
>current current browsing session") but I keep it in
>the session since this also rarely changes so I don't
>want 
>to keep hitting the db to get it.
>

I would have some kind of user object which has a property of 
default_page_id.  The first time the user logs in I would fetch that 
from the database, and then I would cache it so that I wouldn't need to 
go back to the database for it on future requests.

- Perrin

Reply via email to