19 #ifndef CUTELYSTMEMCACHED_H
20 #define CUTELYSTMEMCACHED_H
22 #include <Cutelyst/cutelyst_global.h>
23 #include <Cutelyst/plugin.h>
25 #include <QDataStream>
26 #include <QVersionNumber>
31 class MemcachedPrivate;
203 ServerTemporaryDisabled,
204 ServerMemoryAllocationFailure,
208 Q_ENUM(MemcachedReturnType)
214 void setDefaultConfig(
const QVariantMap &defaultConfig);
227 static bool set(
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
242 template<
typename T>
243 static bool set(
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
260 static bool setByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
278 template<
typename T>
279 static bool setByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
295 static bool add(
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
313 template<
typename T>
314 static bool add(
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
334 static bool addByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
356 template<
typename T>
357 static bool addByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
373 static bool replace(
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
391 template<
typename T>
392 static bool replace(
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
412 static bool replaceByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
434 template<
typename T>
435 static bool replaceByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, MemcachedReturnType *returnType =
nullptr);
451 static QByteArray get(
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
481 template<
typename T>
482 static T get(
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
502 static QByteArray getByKey(
const QString &groupKey,
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
536 template<
typename T>
537 static T getByKey(
const QString &groupKey,
const QString &key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
546 static bool remove(
const QString &key, MemcachedReturnType *returnType =
nullptr);
559 static bool removeByKey(
const QString &groupKey,
const QString &key, MemcachedReturnType *returnType =
nullptr);
567 static bool exist(
const QString &key, MemcachedReturnType *returnType =
nullptr);
579 static bool existByKey(
const QString &groupKey,
const QString &key, MemcachedReturnType *returnType =
nullptr);
601 static bool increment(
const QString &key, uint32_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
620 static bool incrementByKey(
const QString &groupKey,
const QString &key, uint64_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
644 static bool incrementWithInitial(
const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
673 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);
689 static bool decrement(
const QString &key, uint32_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
708 static bool decrementByKey(
const QString &groupKey,
const QString &key, uint64_t offset, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
732 static bool decrementWithInitial(
const QString &key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value =
nullptr,
MemcachedReturnType *returnType =
nullptr);
761 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);
774 static bool cas(
const QString &key,
const QByteArray &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
789 template<
typename T>
790 static bool cas(
const QString &key,
const T &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
808 static bool casByKey(
const QString &groupKey,
const QString &key,
const QByteArray &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
828 template<
typename T>
829 static bool casByKey(
const QString &groupKey,
const QString &key,
const T &value, time_t expiration, uint64_t cas,
MemcachedReturnType *returnType =
nullptr);
864 static QHash<QString, QByteArray> mget(
const QStringList &keys, QHash<QString, uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
880 template<
typename T>
881 static QHash<QString, T> mget(
const QStringList &keys, QHash<QString,uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
900 static QHash<QString, QByteArray> mgetByKey(
const QString &groupKey,
const QStringList &keys, QHash<QString,uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
921 template<
typename T>
922 static QHash<QString, T> mgetByKey(
const QString &groupKey,
const QStringList &keys, QHash<QString,uint64_t> *casValues =
nullptr,
MemcachedReturnType *returnType =
nullptr);
932 static bool touch(
const QString &key, time_t expiration,
MemcachedReturnType *returnType =
nullptr);
947 static bool touchByKey(
const QString &groupKey,
const QString &key, time_t expiration,
MemcachedReturnType *returnType =
nullptr);
957 static QVersionNumber libMemcachedVersion();
960 const QScopedPointer<MemcachedPrivate> d_ptr;
968 template<
typename T>
972 QDataStream out(&data, QIODevice::WriteOnly);
977 template<
typename T>
981 QDataStream out(&data, QIODevice::WriteOnly);
986 template<
typename T>
990 QDataStream out(&data, QIODevice::WriteOnly);
995 template<
typename T>
999 QDataStream out(&data, QIODevice::WriteOnly);
1004 template<
typename T>
1008 QDataStream out(&data, QIODevice::WriteOnly);
1013 template<
typename T>
1017 QDataStream out(&data, QIODevice::WriteOnly);
1022 template<
typename T>
1027 if (!ba.isEmpty()) {
1028 QDataStream in(&ba, QIODevice::ReadOnly);
1034 template<
typename T>
1039 if (!ba.isEmpty()) {
1040 QDataStream in(&ba, QIODevice::ReadOnly);
1046 template<
typename T>
1050 QDataStream out(&data, QIODevice::WriteOnly);
1055 template<
typename T>
1059 QDataStream out(&data, QIODevice::WriteOnly);
1064 template<
typename T>
1067 QHash<QString, T> hash;
1068 QHash<QString,QByteArray> _data =
Memcached::mget(keys, casValues, returnType);
1069 if (!_data.empty()) {
1070 auto i = _data.constBegin();
1071 while (i != _data.constEnd()) {
1073 QDataStream in(i.value());
1075 hash.insert(i.key(), retVal);
1082 template<
typename T>
1085 QHash<QString, T> hash;
1087 if (!_data.empty()) {
1088 auto i = _data.constBegin();
1089 while (i != _data.constEnd()) {
1091 QDataStream in(i.value());
1093 hash.insert(i.key(), retVal);
1102 #endif // CUTELYSTMEMCACHED_H