1717public class CouchbaseSessionRepository implements SessionRepository <CouchbaseSession > {
1818
1919 protected static final String GLOBAL_NAMESPACE = "global" ;
20+ protected static final int SESSION_ENTITY_EXPIRATION_DELAY_IN_SECONDS = 60 ;
2021
2122 private static final Logger log = getLogger (CouchbaseSessionRepository .class );
2223
@@ -49,7 +50,7 @@ public CouchbaseSession createSession() {
4950 sessionData .put (namespace , session .getNamespaceAttributes ());
5051 SessionEntity sessionEntity = new SessionEntity (session .getId (), sessionData );
5152 dao .save (sessionEntity );
52- dao .updateExpirationTime (session .getId (), sessionTimeout );
53+ dao .updateExpirationTime (session .getId (), getSessionEntityExpiration () );
5354
5455 return session ;
5556 }
@@ -59,10 +60,14 @@ public void save(CouchbaseSession session) {
5960 log .debug ("Saving HTTP session with ID {}" , session .getId ());
6061
6162 Map <String , Object > serializedGlobal = serializer .serializeSessionAttributes (session .getGlobalAttributes ());
62- Map <String , Object > serializedNamespace = serializer .serializeSessionAttributes (session .getNamespaceAttributes ());
6363 dao .updateSession (from (serializedGlobal ), GLOBAL_NAMESPACE , session .getId ());
64- dao .updateSession (from (serializedNamespace ), namespace , session .getId ());
65- dao .updateExpirationTime (session .getId (), sessionTimeout );
64+
65+ if (session .isNamespacePersistenceRequired ()) {
66+ Map <String , Object > serializedNamespace = serializer .serializeSessionAttributes (session .getNamespaceAttributes ());
67+ dao .updateSession (from (serializedNamespace ), namespace , session .getId ());
68+ }
69+
70+ dao .updateExpirationTime (session .getId (), getSessionEntityExpiration ());
6671 }
6772
6873 @ Override
@@ -97,4 +102,8 @@ public void delete(String id) {
97102 log .debug ("Deleting HTTP session with ID {}" , id );
98103 dao .delete (id );
99104 }
105+
106+ protected int getSessionEntityExpiration () {
107+ return sessionTimeout + SESSION_ENTITY_EXPIRATION_DELAY_IN_SECONDS ;
108+ }
100109}
0 commit comments