title: I am struggling to understand sessions in CherryPy
body: <p>I recently began a project to migrate our web app from apache + Mod_python to just cherry-py. </p>
  
  <p>There is still a good deal of stuff I still need to do, but for now, it is CherryPy's sessions that are giving me a bit of a headache.</p>
  
  <p>My first question is how do they work? </p>
  
  <p>In Mod_python, we do something like this:</p>
  
  <pre><code>...
  from mod_python import Session
  sess = Session.Session(req, timeout = 60*60, lock=0)
  #req is the request page object.
  </code></pre>
  
  <p>Judging from the CherryPy documentation, all I need to do to start a session is modify the config by adding something like the following:</p>
  
  <pre><code>cherrypy.config.update({
      'tools.sessions.on': True, 
      'tools.sessions.storage_type': 'ram'})
  </code></pre>
  
  <p>The above defaults to a time of 60 minutes (though you can manually set your own), but what if I want to destroy that session and make a new one? Do, I call <code>cherrypy.lib.sessions.expire()</code> in any arbitrary file and then do the <code>cherrypy.config.update</code> thing again? Or, will CherryPy make a new session by itself? What if I want to make a new session with a different expiry time? </p>
  
  <p>Note: When I say arbitrary file, I mean a file that is not running CherryPy (My "config" file imports and gets html back from our other pages much like the standard Publisher that comes with Mod_Python).</p>
  
  <p>I tried making a quick little test file:</p>
  
  <pre><code>import cherrypy
  from cherrypy.lib import sessions
  
  def index(sid=0, secret=None, timeout=30, lock=1):
      cherrypy.session['test'] = 'test'
      cherrypy.lib.sessions.expire()
      return cherrypy.session.get('test','None')
  </code></pre>
  
  <p>The end result is that 'test' is still displayed on the screen. Is this happening because the client side session is expired, but the local one still has data? In that case, how can I check if a session expired or not?</p>
  
  <p>Sorry for the confusing question, but I am confused. </p>
  
  <p>Thanks for all your help!</p>