6#ifndef CUTELYSTMEMCACHED_H
7#define CUTELYSTMEMCACHED_H
9#include <Cutelyst/cutelyst_global.h>
10#include <Cutelyst/plugin.h>
13#include <QVersionNumber>
18class MemcachedPrivate;
226 ServerTemporaryDisabled,
227 ServerMemoryAllocationFailure,
232 Q_ENUM(MemcachedReturnType)
238 void setDefaultConfig(
const QVariantMap &defaultConfig);
252 static bool set(
const QString &key,
253 const QByteArray &value,
255 MemcachedReturnType *returnType =
nullptr);
271 template <
typename T>
272 static bool set(
const QString &key,
275 MemcachedReturnType *returnType =
nullptr);
293 static bool setByKey(
const QString &groupKey,
295 const QByteArray &value,
297 MemcachedReturnType *returnType =
nullptr);
316 template <
typename T>
317 static bool setByKey(
const QString &groupKey,
321 MemcachedReturnType *returnType =
nullptr);
338 static bool add(
const QString &key,
339 const QByteArray &value,
341 MemcachedReturnType *returnType =
nullptr);
361 template <
typename T>
362 static bool add(
const QString &key,
365 MemcachedReturnType *returnType =
nullptr);
386 static bool addByKey(
const QString &groupKey,
388 const QByteArray &value,
390 MemcachedReturnType *returnType =
nullptr);
413 template <
typename T>
414 static bool addByKey(
const QString &groupKey,
418 MemcachedReturnType *returnType =
nullptr);
435 static bool replace(
const QString &key,
436 const QByteArray &value,
438 MemcachedReturnType *returnType =
nullptr);
457 template <
typename T>
458 static bool replace(
const QString &key,
461 MemcachedReturnType *returnType =
nullptr);
482 static bool replaceByKey(
const QString &groupKey,
484 const QByteArray &value,
486 MemcachedReturnType *returnType =
nullptr);
509 template <
typename T>
510 static bool replaceByKey(
const QString &groupKey,
514 MemcachedReturnType *returnType =
nullptr);
534 get(
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
566 template <
typename T>
568 get(
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
590 static QByteArray getByKey(
const QString &groupKey,
592 uint64_t *cas =
nullptr,
593 MemcachedReturnType *returnType =
nullptr);
630 template <
typename T>
631 static T getByKey(
const QString &groupKey,
633 uint64_t *cas =
nullptr,
634 MemcachedReturnType *returnType =
nullptr);
644 static bool remove(
const QString &key, MemcachedReturnType *returnType =
nullptr);
658 static bool removeByKey(
const QString &groupKey,
660 MemcachedReturnType *returnType =
nullptr);
669 static bool exist(
const QString &key, MemcachedReturnType *returnType =
nullptr);
682 static bool existByKey(
const QString &groupKey,
684 MemcachedReturnType *returnType =
nullptr);
708 static bool increment(
const QString &key,
710 uint64_t *value =
nullptr,
734 uint64_t *value =
nullptr,
765 uint64_t *value =
nullptr,
802 uint64_t *value =
nullptr,
820 static bool decrement(
const QString &key,
822 uint64_t *value =
nullptr,
846 uint64_t *value =
nullptr,
877 uint64_t *value =
nullptr,
914 uint64_t *value =
nullptr,
929 static bool cas(
const QString &key,
930 const QByteArray &value,
949 template <
typename T>
950 static bool cas(
const QString &key,
974 static bool casByKey(
const QString &groupKey,
976 const QByteArray &value,
1001 template <
typename T>
1002 static bool casByKey(
const QString &groupKey,
1045 static QHash<QString, QByteArray>
mget(
const QStringList &keys,
1046 QHash<QString, uint64_t> *casValues =
nullptr,
1064 template <
typename T>
1065 static QHash<QString, T>
mget(
const QStringList &keys,
1066 QHash<QString, uint64_t> *casValues =
nullptr,
1088 static QHash<QString, QByteArray>
mgetByKey(
const QString &groupKey,
1089 const QStringList &keys,
1090 QHash<QString, uint64_t> *casValues =
nullptr,
1114 template <
typename T>
1115 static QHash<QString, T>
mgetByKey(
const QString &groupKey,
1116 const QStringList &keys,
1117 QHash<QString, uint64_t> *casValues =
nullptr,
1146 static bool touchByKey(
const QString &groupKey,
1162 const QScopedPointer<MemcachedPrivate> d_ptr;
1170template <
typename T>
1177#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1178 QDataStream out(&data, QIODevice::WriteOnly);
1180 QDataStream out(&data, QIODeviceBase::WriteOnly);
1186template <
typename T>
1194#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1195 QDataStream out(&data, QIODevice::WriteOnly);
1197 QDataStream out(&data, QIODeviceBase::WriteOnly);
1203template <
typename T>
1210#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1211 QDataStream out(&data, QIODevice::WriteOnly);
1213 QDataStream out(&data, QIODeviceBase::WriteOnly);
1219template <
typename T>
1227#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1228 QDataStream out(&data, QIODevice::WriteOnly);
1230 QDataStream out(&data, QIODeviceBase::WriteOnly);
1236template <
typename T>
1243#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1244 QDataStream out(&data, QIODevice::WriteOnly);
1246 QDataStream out(&data, QIODeviceBase::WriteOnly);
1252template <
typename T>
1260#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1261 QDataStream out(&data, QIODevice::WriteOnly);
1263 QDataStream out(&data, QIODeviceBase::WriteOnly);
1269template <
typename T>
1274 if (!ba.isEmpty()) {
1275#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1276 QDataStream in(&ba, QIODevice::ReadOnly);
1278 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1285template <
typename T>
1293 if (!ba.isEmpty()) {
1294#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1295 QDataStream in(&ba, QIODevice::ReadOnly);
1297 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1304template <
typename T>
1312#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1313 QDataStream out(&data, QIODevice::WriteOnly);
1315 QDataStream out(&data, QIODeviceBase::WriteOnly);
1321template <
typename T>
1330#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1331 QDataStream out(&data, QIODevice::WriteOnly);
1333 QDataStream out(&data, QIODeviceBase::WriteOnly);
1339template <
typename T>
1341 QHash<QString, uint64_t> *casValues,
1344 QHash<QString, T> hash;
1345 QHash<QString, QByteArray> _data =
Memcached::mget(keys, casValues, returnType);
1346 if (!_data.empty()) {
1347 auto i = _data.constBegin();
1348 while (i != _data.constEnd()) {
1350 QDataStream in(i.value());
1352 hash.insert(i.key(), retVal);
1359template <
typename T>
1361 const QStringList &keys,
1362 QHash<QString, uint64_t> *casValues,
1365 QHash<QString, T> hash;
1366 QHash<QString, QByteArray> _data =
Memcached::mgetByKey(groupKey, keys, casValues, returnType);
1367 if (!_data.empty()) {
1368 auto i = _data.constBegin();
1369 while (i != _data.constEnd()) {
1371 QDataStream in(i.value());
1373 hash.insert(i.key(), retVal);
The Cutelyst Application.
static bool replaceByKey(const QString &groupKey, const QString &key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool incrementByKey(const QString &groupKey, const QString &key, uint64_t offset, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static bool add(const QString &key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
@ MemoryAllocationFailure
static QByteArray get(const QString &key, uint64_t *cas=nullptr, MemcachedReturnType *returnType=nullptr)
static bool casByKey(const QString &groupKey, const QString &key, const QByteArray &value, time_t expiration, uint64_t cas, MemcachedReturnType *returnType=nullptr)
static bool increment(const QString &key, uint32_t offset, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
virtual bool setup(Application *app) override
static bool flush(time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool decrementByKey(const QString &groupKey, const QString &key, uint64_t offset, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static bool incrementWithInitial(const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static bool cas(const QString &key, const QByteArray &value, time_t expiration, uint64_t cas, MemcachedReturnType *returnType=nullptr)
static bool touch(const QString &key, time_t expiration, MemcachedReturnType *returnType=nullptr)
static QHash< QString, QByteArray > mgetByKey(const QString &groupKey, const QStringList &keys, QHash< QString, uint64_t > *casValues=nullptr, MemcachedReturnType *returnType=nullptr)
static bool flushBuffers(MemcachedReturnType *returnType=nullptr)
static bool decrementWithInitialByKey(const QString &groupKey, const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static const time_t expirationNotAdd
static bool set(const QString &key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool incrementWithInitialByKey(const QString &groupKey, const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static bool decrement(const QString &key, uint32_t offset, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static QString errorString(Context *c, MemcachedReturnType rt)
static bool touchByKey(const QString &groupKey, const QString &key, time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool decrementWithInitial(const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static bool setByKey(const QString &groupKey, const QString &key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static QHash< QString, QByteArray > mget(const QStringList &keys, QHash< QString, uint64_t > *casValues=nullptr, MemcachedReturnType *returnType=nullptr)
static bool replace(const QString &key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool addByKey(const QString &groupKey, const QString &key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static QByteArray getByKey(const QString &groupKey, const QString &key, uint64_t *cas=nullptr, MemcachedReturnType *returnType=nullptr)
Memcached(Application *parent)
static QVersionNumber libMemcachedVersion()
Returns the version of the currently used libmemcached.
Plugin(Application *parent)
The Cutelyst namespace holds all public Cutelyst API.