6 #ifndef CUTELYSTMEMCACHED_H
7 #define CUTELYSTMEMCACHED_H
9 #include <Cutelyst/cutelyst_global.h>
10 #include <Cutelyst/plugin.h>
12 #include <QDataStream>
13 #include <QVersionNumber>
18 class MemcachedPrivate;
190 ServerTemporaryDisabled,
191 ServerMemoryAllocationFailure,
195 Q_ENUM(MemcachedReturnType)
201 void setDefaultConfig(
const QVariantMap &defaultConfig);
214 static bool set(
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
229 template<
typename T>
230 static bool set(
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
247 static bool setByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
265 template<
typename T>
266 static bool setByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
282 static bool add(
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
300 template<
typename T>
301 static bool add(
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
321 static bool addByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
343 template<
typename T>
344 static bool addByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
360 static bool replace(
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
378 template<
typename T>
379 static bool replace(
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
399 static bool replaceByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
421 template<
typename T>
422 static bool replaceByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
438 static QByteArray get(
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
468 template<
typename T>
469 static T get(
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
489 static QByteArray getByKey(
const QString &groupKey,
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
523 template<
typename T>
524 static T getByKey(
const QString &groupKey,
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
533 static bool remove(
const QString &key, MemcachedReturnType *returnType =
nullptr);
546 static bool removeByKey(
const QString &groupKey,
const QString &key, MemcachedReturnType *returnType =
nullptr);
554 static bool exist(
const QString &key, MemcachedReturnType *returnType =
nullptr);
566 static bool existByKey(
const QString &groupKey,
const QString &key, MemcachedReturnType *returnType =
nullptr);
588 static bool increment(
const QString &key, uint32_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
607 static bool incrementByKey(
const QString &groupKey,
const QString &key, uint64_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
631 static bool incrementWithInitial(
const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
660 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);
676 static bool decrement(
const QString &key, uint32_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
695 static bool decrementByKey(
const QString &groupKey,
const QString &key, uint64_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
719 static bool decrementWithInitial(
const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
748 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);
761 static bool cas(
const QString &key,
const QByteArray &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
776 template<
typename T>
777 static bool cas(
const QString &key,
const T &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
795 static bool casByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
815 template<
typename T>
816 static bool casByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
851 static QHash<QString, QByteArray> mget(
const QStringList &keys, QHash<QString, uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
867 template<
typename T>
868 static QHash<QString, T> mget(
const QStringList &keys, QHash<QString,uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
887 static QHash<QString, QByteArray> mgetByKey(
const QString &groupKey,
const QStringList &keys, QHash<QString,uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
908 template<
typename T>
909 static QHash<QString, T> mgetByKey(
const QString &groupKey,
const QStringList &keys, QHash<QString,uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
919 static bool touch(
const QString &key, time_t expiration,
MemcachedReturnType *returnType =
nullptr);
934 static bool touchByKey(
const QString &groupKey,
const QString &key, time_t expiration,
MemcachedReturnType *returnType =
nullptr);
944 static QVersionNumber libMemcachedVersion();
947 const QScopedPointer<MemcachedPrivate> d_ptr;
955 template<
typename T>
959 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
960 QDataStream out(&data, QIODevice::WriteOnly);
962 QDataStream out(&data, QIODeviceBase::WriteOnly);
968 template<
typename T>
972 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
973 QDataStream out(&data, QIODevice::WriteOnly);
975 QDataStream out(&data, QIODeviceBase::WriteOnly);
981 template<
typename T>
985 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
986 QDataStream out(&data, QIODevice::WriteOnly);
988 QDataStream out(&data, QIODeviceBase::WriteOnly);
994 template<
typename T>
998 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
999 QDataStream out(&data, QIODevice::WriteOnly);
1001 QDataStream out(&data, QIODeviceBase::WriteOnly);
1007 template<
typename T>
1011 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1012 QDataStream out(&data, QIODevice::WriteOnly);
1014 QDataStream out(&data, QIODeviceBase::WriteOnly);
1020 template<
typename T>
1024 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1025 QDataStream out(&data, QIODevice::WriteOnly);
1027 QDataStream out(&data, QIODeviceBase::WriteOnly);
1033 template<
typename T>
1038 if (!ba.isEmpty()) {
1039 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1040 QDataStream in(&ba, QIODevice::ReadOnly);
1042 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1049 template<
typename T>
1054 if (!ba.isEmpty()) {
1055 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1056 QDataStream in(&ba, QIODevice::ReadOnly);
1058 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1065 template<
typename T>
1069 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1070 QDataStream out(&data, QIODevice::WriteOnly);
1072 QDataStream out(&data, QIODeviceBase::WriteOnly);
1078 template<
typename T>
1082 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1083 QDataStream out(&data, QIODevice::WriteOnly);
1085 QDataStream out(&data, QIODeviceBase::WriteOnly);
1091 template<
typename T>
1094 QHash<QString, T> hash;
1095 QHash<QString,QByteArray> _data =
Memcached::mget(keys, casValues, returnType);
1096 if (!_data.empty()) {
1097 auto i = _data.constBegin();
1098 while (i != _data.constEnd()) {
1100 QDataStream in(i.value());
1102 hash.insert(i.key(), retVal);
1109 template<
typename T>
1112 QHash<QString, T> hash;
1114 if (!_data.empty()) {
1115 auto i = _data.constBegin();
1116 while (i != _data.constEnd()) {
1118 QDataStream in(i.value());
1120 hash.insert(i.key(), retVal);
The Cutelyst Application.
Cutelyst Memcached plugin.
static bool replaceByKey(const QString &groupKey, const QString &key, const QByteArray &value, time_t expiration, 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 cas(const QString &key, const QByteArray &value, time_t expiration, uint64_t cas, MemcachedReturnType *returnType=nullptr)
static QHash< QString, QByteArray > mgetByKey(const QString &groupKey, const QStringList &keys, QHash< QString, uint64_t > *casValues=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 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)
The Cutelyst namespace holds all public Cutelyst API.