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;
189 ServerTemporaryDisabled,
190 ServerMemoryAllocationFailure,
194 Q_ENUM(MemcachedReturnType)
200 void setDefaultConfig(
const QVariantMap &defaultConfig);
213 static bool set(
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
228 template<
typename T>
229 static bool set(
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
246 static bool setByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
264 template<
typename T>
265 static bool setByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
281 static bool add(
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
299 template<
typename T>
300 static bool add(
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
320 static bool addByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
342 template<
typename T>
343 static bool addByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
359 static bool replace(
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
377 template<
typename T>
378 static bool replace(
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
398 static bool replaceByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
420 template<
typename T>
421 static bool replaceByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
437 static QByteArray get(
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
467 template<
typename T>
468 static T get(
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
488 static QByteArray getByKey(
const QString &groupKey,
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
522 template<
typename T>
523 static T getByKey(
const QString &groupKey,
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
532 static bool remove(
const QString &key, MemcachedReturnType *returnType =
nullptr);
545 static bool removeByKey(
const QString &groupKey,
const QString &key, MemcachedReturnType *returnType =
nullptr);
553 static bool exist(
const QString &key, MemcachedReturnType *returnType =
nullptr);
565 static bool existByKey(
const QString &groupKey,
const QString &key, MemcachedReturnType *returnType =
nullptr);
587 static bool increment(
const QString &key, uint32_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
606 static bool incrementByKey(
const QString &groupKey,
const QString &key, uint64_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
630 static bool incrementWithInitial(
const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
659 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);
675 static bool decrement(
const QString &key, uint32_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
694 static bool decrementByKey(
const QString &groupKey,
const QString &key, uint64_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
718 static bool decrementWithInitial(
const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
747 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);
760 static bool cas(
const QString &key,
const QByteArray &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
775 template<
typename T>
776 static bool cas(
const QString &key,
const T &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
794 static bool casByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
814 template<
typename T>
815 static bool casByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
850 static QHash<QString, QByteArray> mget(
const QStringList &keys, QHash<QString, uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
866 template<
typename T>
867 static QHash<QString, T> mget(
const QStringList &keys, QHash<QString,uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
886 static QHash<QString, QByteArray> mgetByKey(
const QString &groupKey,
const QStringList &keys, QHash<QString,uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
907 template<
typename T>
908 static QHash<QString, T> mgetByKey(
const QString &groupKey,
const QStringList &keys, QHash<QString,uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
918 static bool touch(
const QString &key, time_t expiration,
MemcachedReturnType *returnType =
nullptr);
933 static bool touchByKey(
const QString &groupKey,
const QString &key, time_t expiration,
MemcachedReturnType *returnType =
nullptr);
943 static QVersionNumber libMemcachedVersion();
946 const QScopedPointer<MemcachedPrivate> d_ptr;
954 template<
typename T>
958 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
959 QDataStream out(&data, QIODevice::WriteOnly);
961 QDataStream out(&data, QIODeviceBase::WriteOnly);
967 template<
typename T>
971 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
972 QDataStream out(&data, QIODevice::WriteOnly);
974 QDataStream out(&data, QIODeviceBase::WriteOnly);
980 template<
typename T>
984 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
985 QDataStream out(&data, QIODevice::WriteOnly);
987 QDataStream out(&data, QIODeviceBase::WriteOnly);
993 template<
typename T>
997 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
998 QDataStream out(&data, QIODevice::WriteOnly);
1000 QDataStream out(&data, QIODeviceBase::WriteOnly);
1006 template<
typename T>
1010 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1011 QDataStream out(&data, QIODevice::WriteOnly);
1013 QDataStream out(&data, QIODeviceBase::WriteOnly);
1019 template<
typename T>
1023 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1024 QDataStream out(&data, QIODevice::WriteOnly);
1026 QDataStream out(&data, QIODeviceBase::WriteOnly);
1032 template<
typename T>
1037 if (!ba.isEmpty()) {
1038 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1039 QDataStream in(&ba, QIODevice::ReadOnly);
1041 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1048 template<
typename T>
1053 if (!ba.isEmpty()) {
1054 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1055 QDataStream in(&ba, QIODevice::ReadOnly);
1057 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1064 template<
typename T>
1068 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1069 QDataStream out(&data, QIODevice::WriteOnly);
1071 QDataStream out(&data, QIODeviceBase::WriteOnly);
1077 template<
typename T>
1081 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1082 QDataStream out(&data, QIODevice::WriteOnly);
1084 QDataStream out(&data, QIODeviceBase::WriteOnly);
1090 template<
typename T>
1093 QHash<QString, T> hash;
1094 QHash<QString,QByteArray> _data =
Memcached::mget(keys, casValues, returnType);
1095 if (!_data.empty()) {
1096 auto i = _data.constBegin();
1097 while (i != _data.constEnd()) {
1099 QDataStream in(i.value());
1101 hash.insert(i.key(), retVal);
1108 template<
typename T>
1111 QHash<QString, T> hash;
1113 if (!_data.empty()) {
1114 auto i = _data.constBegin();
1115 while (i != _data.constEnd()) {
1117 QDataStream in(i.value());
1119 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.