Optimisation - only save session if data added by application
[catagits/Catalyst-Plugin-Session.git] / lib / Catalyst / Plugin / Session.pm
index ee3347e..168b60f 100644 (file)
@@ -13,7 +13,7 @@ use Carp;
 
 use namespace::clean -except => 'meta';
 
-our $VERSION = '0.29';
+our $VERSION = '0.31';
 $VERSION = eval $VERSION;
 
 my @session_data_accessors; # used in delete_session
@@ -499,8 +499,7 @@ sub initialize_session_data {
 
     my $now = time;
 
-    return $c->_session(
-        {
+    my $session_data = {
             __created => $now,
             __updated => $now,
 
@@ -514,8 +513,12 @@ sub initialize_session_data {
                 ? ( __user_agent => $c->request->user_agent||'' )
                 : ()
             ),
-        }
-    );
+    };
+
+    # Only save this session if data is added by the application
+    $c->_session_data_sig( Object::Signature::signature($session_data) );
+
+    return $c->_session($session_data);
 }
 
 sub generate_session_id {
@@ -578,7 +581,7 @@ sub dump_these {
     (
         $c->maybe::next::method(),
 
-        $c->sessionid
+        $c->_sessionid
         ? ( [ "Session ID" => $c->sessionid ], [ Session => $c->session ], )
         : ()
     );
@@ -788,7 +791,8 @@ expiry time for the whole session).
 
 For example:
 
-    __PACKAGE__->config('Plugin::Session' => { expires => 1000000000000 }); # forever
+    __PACKAGE__->config('Plugin::Session' => { expires => 10000000000 }); # "forever" 
+    (NB If this number is too large, Y2K38 breakage could result.)
 
     # later
 
@@ -1105,11 +1109,8 @@ changes by request a
 
 =back
 
-If this is a concern in your application, a soon-to-be-developed locking
-solution is the only safe way to go. This will have a bigger overhead.
-
-For applications where any given user is only making one request at a time this
-plugin should be safe enough.
+For applications where any given user's session is only making one request
+at a time this plugin should be safe enough.
 
 =head1 AUTHORS