SessionDynamicStore

Session store using memory and files.

class SessionDynamicStore.SessionDynamicStore(app)

Bases: SessionStore

Stores the session in memory and in files.

To use this Session Store, set SessionStore in Application.config to ‘Dynamic’. Other variables which can be set in Application.config are:

‘MaxDynamicMemorySessions’, which sets the maximum number of sessions that can be in memory at one time. Default is 10,000.

‘DynamicSessionTimeout’, which sets the default time for a session to stay in memory with no activity. Default is 15 minutes. When specifying this in Application.config, use minutes.

One-shot sessions (usually created by crawler bots) aren’t moved to FileStore on periodical clean-up. They are still saved on SessionStore shutdown. This reduces the number of files in the Sessions directory.

__init__(app)

Create both a file and a memory store.

application()

Return the application owning the session store.

cleanStaleSessions(task=None)

Clean stale sessions.

Called by the Application to tell this store to clean out all sessions that have exceeded their lifetime. We want to have their native class functions handle it, though.

Ideally, intervalSweep would be run more often than the cleanStaleSessions functions for the actual stores. This may need to wait until we get the TaskKit in place, though.

The problem is the FileStore.cleanStaleSessions() method can take a while to run. So here, we only run the file sweep every fourth time.

clear()

Clear the session store in memory and remove all session files.

decoder()

Return the value deserializer for the store.

encoder()

Return the value serializer for the store.

get(key, default=None)

Return value if key available, else return the default.

has_key(key)

Check whether the session store has a given key.

intervalSweep()

The session sweeper interval function.

The interval function moves sessions from memory to file and can be run more often than the full cleanStaleSessions function.

items()

Return a list with the (key, value) pairs for all sessions.

iteritems()

Return an iterator over the (key, value) pairs for all sessions.

iterkeys()

Return an iterator over the stored session keys.

itervalues()

Return an iterator over the stored values of all sessions.

keys()

Return a list with all keys of all the stored sessions.

memoryKeysInAccessTimeOrder()

Fetch memory store’s keys in ascending order of last access time.

moveToFile(key)

Move the value for a session from memory to file.

moveToMemory(key)

Move the value for a session from file to memory.

pop(key, default=<class 'MiscUtils.NoDefault'>)

Return value if key available, else default (also remove key).

setEncoderDecoder(encoder, decoder)

Set the serializer and deserializer for the store.

setdefault(key, default=None)

Return value if key available, else default (also setting it).

storeAllSessions()

Permanently save all sessions in the store.

storeSession(session)

Save potentially changed session in the store.

values()

Return a list with the values of all stored sessions.