Skip to content

Commit 89a0fa5

Browse files
committed
Add option RetainSessions
This allows disabling the feature that MemoryStore sessions are saved when the server stops and restored when it starts again.
1 parent 74f5a03 commit 89a0fa5

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

WebKit/Application.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
SessionPrefix = '',
5353
SessionName = '_SID_',
5454
AlwaysSaveSessions = True,
55+
RetainSessions = True,
5556
IgnoreInvalidSession = True,
5657
UseAutomaticPathSessions = False,
5758
UseCookieSessions = True,
@@ -220,6 +221,7 @@ def initSessions(self):
220221
self.defaultConfig()['SessionName'])
221222
self._autoPathSessions = self.setting('UseAutomaticPathSessions')
222223
self._alwaysSaveSessions = self.setting('AlwaysSaveSessions')
224+
self._retainSessions = self.setting('RetainSessions')
223225
moduleName = self.setting('SessionModule')
224226
className = moduleName.rsplit('.', 1)[-1]
225227
try:

WebKit/Configs/Application.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ MaxDynamicMemorySessions = 10000
5959
DynamicSessionTimeout = 15
6060
# Set to False if sessions should be saved only when dirty:
6161
AlwaysSaveSessions = True
62+
# Set to False if sessions should not be retained when the server stops:
63+
RetainSessions = True
6264
# The session ID can be prefixed with "hostname" or any other string:
6365
SessionPrefix = None # no prefix to session ID
6466
IgnoreInvalidSession = True

WebKit/SessionFileStore.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ class SessionFileStore(SessionStore):
2828

2929
## Init ##
3030

31-
def __init__(self, app, restoreFiles=True):
31+
def __init__(self, app, restoreFiles=None):
3232
"""Initialize the session file store.
3333
3434
If restoreFiles is true, and sessions have been saved to file,
3535
the store will be initialized from these files.
3636
"""
3737
SessionStore.__init__(self, app)
38+
if restoreFiles is None:
39+
restoreFiles = self._retain
3840
self._sessionDir = app._sessionDir
3941
self._lock = threading.RLock()
4042
if not restoreFiles:

WebKit/SessionMemoryStore.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ class SessionMemoryStore(SessionStore):
1515

1616
## Init ##
1717

18-
def __init__(self, app, restoreFiles=True):
18+
def __init__(self, app, restoreFiles=None):
1919
"""Initialize the session memory store.
2020
2121
If restoreFiles is true, and sessions have been saved to file,
2222
the store will be initialized from these files.
2323
"""
2424
SessionStore.__init__(self, app)
2525
self._store = {}
26+
if restoreFiles is None:
27+
restoreFiles = self._retain
2628
if restoreFiles:
2729
filestore = SessionFileStore(app)
2830
for key in filestore:
@@ -31,6 +33,7 @@ def __init__(self, app, restoreFiles=True):
3133
except Exception:
3234
app.handleException()
3335
filestore.clear()
36+
self._restoreFiles = restoreFiles
3437

3538

3639
## Access ##
@@ -96,6 +99,7 @@ def storeSession(self, session):
9699

97100
def storeAllSessions(self):
98101
"""Permanently save all sessions in the store."""
99-
filestore = SessionFileStore(self._app)
100-
for key, session in self.items():
101-
filestore[key] = session
102+
if self._restoreFiles:
103+
filestore = SessionFileStore(self._app)
104+
for key, session in self.items():
105+
filestore[key] = session

WebKit/SessionShelveStore.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ class SessionShelveStore(SessionStore):
1919

2020
## Init ##
2121

22-
def __init__(self, app, restoreFiles=True, filename=None):
22+
def __init__(self, app, restoreFiles=None, filename=None):
2323
"""Initialize the session shelf.
2424
2525
If restoreFiles is true, existing shelve file(s) will be reused.
2626
"""
2727
SessionStore.__init__(self, app)
2828
filename = os.path.join(app._sessionDir, filename or self._filename)
29+
if restoreFiles is None:
30+
restoreFiles = self._retain
2931
flag = 'c' if restoreFiles else 'n'
3032
self._store = shelve.open(filename,
3133
flag=flag, protocol=maxPickleProtocol)

WebKit/SessionStore.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(self, app):
6060
"""
6161
self._app = app
6262
self._alwaysSave = app._alwaysSaveSessions
63+
self._retain = app._retainSessions
6364
self._encoder = dumpWithHighestProtocol
6465
self._decoder = load
6566

0 commit comments

Comments
 (0)