cutelyst 5.0.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::MemcachedSessionStore Class Referencefinal

Memcached based session store. More...

#include <Cutelyst/Pugins/MemcachedSessionStore/MemcachedSessionStore>

Inheritance diagram for Cutelyst::MemcachedSessionStore:

Public Member Functions

 MemcachedSessionStore (Application *app, QObject *parent=nullptr)
 ~MemcachedSessionStore () override
bool deleteExpiredSessions (Context *c, quint64 expires) override
bool deleteSessionData (Context *c, const QByteArray &sid, const QString &key) override
QVariant getSessionData (Context *c, const QByteArray &sid, const QString &key, const QVariant &defaultValue) override
void setGroupKey (const QByteArray &groupKey)
bool storeSessionData (Context *c, const QByteArray &sid, const QString &key, const QVariant &value) override
Public Member Functions inherited from Cutelyst::SessionStore
 SessionStore (QObject *parent=nullptr)

Detailed Description

This session store saves session data to Memcached servers using the Memcached plugin.

Note
The memcached server does not guarantee the existence of the session data. It might for example delete the data because it runs out of memory and deletes session data. So be careful when using this plugin to store sessions.

Configuration

The MemcachedSessionStore plugin can be configured in the application configuration file in the Cutelyst_MemcachedSessionStore_Plugin section:

group_key

Type: string
Default: empty

Sets an optional group key to store the data on a specific server.

Configuration example

[Cutelyst_MemcachedSessionStore_Plugin]
group_key=sessions

Usage example

#include <Cutelyst/Plugins/Memcached/Memcached>
#include <Cutelyst/Plugins/MemcachedSessionStore/MemcachedSessionStore>
bool MyCutelystApp::init()
{
// other initilization stuff
// ...
new Memcached(this);
auto sess = new Session(this);
sess->setStorage(new MemcachedSessionStore(this));
// maybe more initilization stuff
// ...
}
MemcachedSessionStore(Application *app, QObject *parent=nullptr)
Cutelyst Memcached plugin.
Definition memcached.h:168
Plugin providing methods for session management.
Definition session.h:161

Build requirements

To build this plugin you need the development and header files for libmemcached and have to enable the Memcached plugin. If the Memcached plugin is enabled, the MemcachedSessionStore plugin will be enabled automatically, too. To disable the build of the MemcachedSessionStore plugin, run cmake with -DPLUGIN_MEMCACHEDSESSIONSTORE:BOOL=OFF.

Logging category
cutelyst.plugin.memcachedsessionstore
Logging with Cutelyst
Since
Cutelyst 1.11.0

Definition at line 77 of file memcachedsessionstore.h.

Constructor & Destructor Documentation

◆ MemcachedSessionStore()

MemcachedSessionStore::MemcachedSessionStore ( Cutelyst::Application * app,
QObject * parent = nullptr )
explicit

Constructs a new MemcachedSessionStore object with the given parent and app. The pointer to the Application object is used to load the plugin configuration from the configuration file section Cutelyst_MemcachedSessionStore_Plugin.

Definition at line 27 of file memcachedsessionstore.cpp.

References MemcachedSessionStore(), Cutelyst::SessionStore::SessionStore(), Cutelyst::Engine::config(), and Cutelyst::Application::engine().

Referenced by MemcachedSessionStore(), deleteSessionData(), getSessionData(), setGroupKey(), and storeSessionData().

◆ ~MemcachedSessionStore()

MemcachedSessionStore::~MemcachedSessionStore ( )
overridedefault

Deconstructs the MemcachedSessionStore object

References deleteExpiredSessions(), deleteSessionData(), getSessionData(), setGroupKey(), and storeSessionData().

Member Function Documentation

◆ deleteExpiredSessions()

bool MemcachedSessionStore::deleteExpiredSessions ( Context * c,
quint64 expires )
overridevirtual

Removes all expired sessions which are above expires.

Implements Cutelyst::SessionStore.

Definition at line 78 of file memcachedsessionstore.cpp.

Referenced by ~MemcachedSessionStore().

◆ deleteSessionData()

bool MemcachedSessionStore::deleteSessionData ( Context * c,
const QByteArray & sid,
const QString & key )
overridevirtual

Removes all session data for the given session id sid and key.

Implements Cutelyst::SessionStore.

Definition at line 67 of file memcachedsessionstore.cpp.

References MemcachedSessionStore(), and Cutelyst::Context::setStash().

Referenced by ~MemcachedSessionStore().

◆ getSessionData()

QVariant MemcachedSessionStore::getSessionData ( Context * c,
const QByteArray & sid,
const QString & key,
const QVariant & defaultValue )
overridevirtual

Returns the session data for the given session id sid and key, if key does not exist returns defaultValue.

Implements Cutelyst::SessionStore.

Definition at line 41 of file memcachedsessionstore.cpp.

References MemcachedSessionStore().

Referenced by ~MemcachedSessionStore().

◆ setGroupKey()

void MemcachedSessionStore::setGroupKey ( const QByteArray & groupKey)

Sets the groupKey to define the servers to store the sessions on. This can also be set in the configuration file.

Definition at line 86 of file memcachedsessionstore.cpp.

References MemcachedSessionStore().

Referenced by ~MemcachedSessionStore().

◆ storeSessionData()

bool MemcachedSessionStore::storeSessionData ( Context * c,
const QByteArray & sid,
const QString & key,
const QVariant & value )
overridevirtual

Stores the session data for the given session id sid and key to value.

Implements Cutelyst::SessionStore.

Definition at line 53 of file memcachedsessionstore.cpp.

References MemcachedSessionStore(), and Cutelyst::Context::setStash().

Referenced by ~MemcachedSessionStore().