7#include <Cutelyst/cutelyst_global.h>
8#include <Cutelyst/plugin.h>
12#include <QVersionNumber>
17class MemcachedPrivate;
227 ServerTemporaryDisabled,
228 ServerMemoryAllocationFailure,
233 Q_ENUM(MemcachedReturnType)
239 void setDefaultConfig(
const QVariantMap &defaultConfig);
253 static bool set(QByteArrayView key,
254 const QByteArray &value,
256 MemcachedReturnType *returnType =
nullptr);
262 inline static bool set(QByteArrayView key,
263 const QByteArray &value,
264 std::chrono::seconds expiration,
265 MemcachedReturnType *returnType =
nullptr);
281 template <
typename T>
282 static bool set(QByteArrayView key,
285 MemcachedReturnType *returnType =
nullptr);
291 template <
typename T>
292 static bool set(QByteArrayView key,
294 std::chrono::seconds expiration,
295 MemcachedReturnType *returnType =
nullptr);
313 static bool setByKey(QByteArrayView groupKey,
315 const QByteArray &value,
317 MemcachedReturnType *returnType =
nullptr);
323 inline static bool setByKey(QByteArrayView groupKey,
325 const QByteArray &value,
326 std::chrono::seconds expiration,
327 MemcachedReturnType *returnType =
nullptr);
346 template <
typename T>
347 static bool setByKey(QByteArrayView groupKey,
351 MemcachedReturnType *returnType =
nullptr);
357 template <
typename T>
358 static bool setByKey(QByteArrayView groupKey,
361 std::chrono::seconds expiration,
362 MemcachedReturnType *returnType =
nullptr);
379 static bool add(QByteArrayView key,
380 const QByteArray &value,
382 MemcachedReturnType *returnType =
nullptr);
388 inline static bool add(QByteArrayView key,
389 const QByteArray &value,
390 std::chrono::seconds expiration,
391 MemcachedReturnType *returnType =
nullptr);
411 template <
typename T>
412 static bool add(QByteArrayView key,
415 MemcachedReturnType *returnType =
nullptr);
421 template <
typename T>
422 static bool add(QByteArrayView key,
424 std::chrono::seconds expiration,
425 MemcachedReturnType *returnType =
nullptr);
446 static bool addByKey(QByteArrayView groupKey,
448 const QByteArray &value,
450 MemcachedReturnType *returnType =
nullptr);
456 inline static bool addByKey(QByteArrayView groupKey,
458 const QByteArray &value,
459 std::chrono::seconds expiration,
460 MemcachedReturnType *returnType =
nullptr);
483 template <
typename T>
484 static bool addByKey(QByteArrayView groupKey,
488 MemcachedReturnType *returnType =
nullptr);
494 template <
typename T>
495 static bool addByKey(QByteArrayView groupKey,
498 std::chrono::seconds expiration,
499 MemcachedReturnType *returnType =
nullptr);
516 static bool replace(QByteArrayView key,
517 const QByteArray &value,
519 MemcachedReturnType *returnType =
nullptr);
525 inline static bool replace(QByteArrayView key,
526 const QByteArray &value,
527 std::chrono::seconds expiration,
528 MemcachedReturnType *returnType =
nullptr);
547 template <
typename T>
548 static bool replace(QByteArrayView key,
551 MemcachedReturnType *returnType =
nullptr);
557 template <
typename T>
558 static bool replace(QByteArrayView key,
560 std::chrono::seconds expiration,
561 MemcachedReturnType *returnType =
nullptr);
582 static bool replaceByKey(QByteArrayView groupKey,
584 const QByteArray &value,
586 MemcachedReturnType *returnType =
nullptr);
592 inline static bool replaceByKey(QByteArrayView groupKey,
594 const QByteArray &value,
595 std::chrono::seconds expiration,
596 MemcachedReturnType *returnType =
nullptr);
619 template <
typename T>
620 static bool replaceByKey(QByteArrayView groupKey,
624 MemcachedReturnType *returnType =
nullptr);
630 template <
typename T>
631 static bool replaceByKey(QByteArrayView groupKey,
634 std::chrono::seconds expiration,
635 MemcachedReturnType *returnType =
nullptr);
655 get(QByteArrayView key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
687 template <
typename T>
689 get(QByteArrayView key, uint64_t *cas =
nullptr, MemcachedReturnType *returnType =
nullptr);
711 static QByteArray getByKey(QByteArrayView groupKey,
713 uint64_t *cas =
nullptr,
714 MemcachedReturnType *returnType =
nullptr);
751 template <
typename T>
752 static T getByKey(QByteArrayView groupKey,
754 uint64_t *cas =
nullptr,
755 MemcachedReturnType *returnType =
nullptr);
765 static bool remove(QByteArrayView key, MemcachedReturnType *returnType =
nullptr);
779 static bool removeByKey(QByteArrayView groupKey,
781 MemcachedReturnType *returnType =
nullptr);
790 static bool exist(QByteArrayView key, MemcachedReturnType *returnType =
nullptr);
803 static bool existByKey(QByteArrayView groupKey,
805 MemcachedReturnType *returnType =
nullptr);
838 static bool increment(QByteArrayView key,
840 uint64_t *value =
nullptr,
861 static bool incrementByKey(QByteArrayView groupKey,
864 uint64_t *value =
nullptr,
891 static bool incrementWithInitial(QByteArrayView key,
895 uint64_t *value =
nullptr,
902 inline static bool incrementWithInitial(QByteArrayView key,
905 std::chrono::seconds expiration,
906 uint64_t *value =
nullptr,
938 static bool incrementWithInitialByKey(QByteArrayView groupKey,
943 uint64_t *value =
nullptr,
950 inline static bool incrementWithInitialByKey(QByteArrayView groupKey,
954 std::chrono::seconds expiration,
955 uint64_t *value =
nullptr,
973 static bool decrement(QByteArrayView key,
975 uint64_t *value =
nullptr,
996 static bool decrementByKey(QByteArrayView groupKey,
999 uint64_t *value =
nullptr,
1026 static bool decrementWithInitial(QByteArrayView key,
1030 uint64_t *value =
nullptr,
1037 inline static bool decrementWithInitial(QByteArrayView key,
1040 std::chrono::seconds expiration,
1041 uint64_t *value =
nullptr,
1073 static bool decrementWithInitialByKey(QByteArrayView groupKey,
1078 uint64_t *value =
nullptr,
1085 inline static bool decrementWithInitialByKey(QByteArrayView groupKey,
1089 std::chrono::seconds expiration,
1090 uint64_t *value =
nullptr,
1105 static bool cas(QByteArrayView key,
1106 const QByteArray &value,
1115 inline static bool cas(QByteArrayView key,
1116 const QByteArray &value,
1117 std::chrono::seconds expiration,
1135 template <
typename T>
1136 static bool cas(QByteArrayView key,
1146 template <
typename T>
1147 static bool cas(QByteArrayView key,
1149 std::chrono::seconds expiration,
1171 static bool casByKey(QByteArrayView groupKey,
1173 const QByteArray &value,
1182 inline static bool casByKey(QByteArrayView groupKey,
1184 const QByteArray &value,
1185 std::chrono::seconds expiration,
1209 template <
typename T>
1210 static bool casByKey(QByteArrayView groupKey,
1221 template <
typename T>
1222 static bool casByKey(QByteArrayView groupKey,
1225 std::chrono::seconds expiration,
1256 inline static bool flush(std::chrono::seconds expiration,
1272 static QHash<QByteArray, QByteArray> mget(
const QByteArrayList &keys,
1273 QHash<QByteArray, uint64_t> *casValues =
nullptr,
1291 template <
typename T>
1292 static QHash<QByteArray, T> mget(
const QByteArrayList &keys,
1293 QHash<QByteArray, uint64_t> *casValues =
nullptr,
1315 static QHash<QByteArray, QByteArray> mgetByKey(QByteArrayView groupKey,
1316 const QByteArrayList &keys,
1317 QHash<QByteArray, uint64_t> *casValues =
nullptr,
1341 template <
typename T>
1342 static QHash<QByteArray, T> mgetByKey(QByteArrayView groupKey,
1343 const QByteArrayList &keys,
1344 QHash<QByteArray, uint64_t> *casValues =
nullptr,
1363 inline static bool touch(QByteArrayView key,
1364 std::chrono::seconds expiration,
1381 static bool touchByKey(QByteArrayView groupKey,
1390 inline static bool touchByKey(QByteArrayView groupKey,
1392 std::chrono::seconds expiration,
1403 static QVersionNumber libMemcachedVersion();
1412 const std::unique_ptr<MemcachedPrivate> d_ptr;
1416 const QByteArray &value,
1417 std::chrono::seconds expiration,
1420 return Memcached::set(key, value, expiration.count(), returnType);
1423template <
typename T>
1430 QDataStream out(&data, QIODeviceBase::WriteOnly);
1435template <
typename T>
1438 std::chrono::seconds expiration,
1441 return Memcached::set<T>(key, value, expiration.count(), returnType);
1446 const QByteArray &value,
1447 std::chrono::seconds expiration,
1453template <
typename T>
1461 QDataStream out(&data, QIODeviceBase::WriteOnly);
1466template <
typename T>
1470 std::chrono::seconds expiration,
1473 return Memcached::setByKey<T>(groupKey, key, value, expiration.count(), returnType);
1477 const QByteArray &value,
1478 std::chrono::seconds expiration,
1481 return Memcached::add(key, value, expiration.count(), returnType);
1484template <
typename T>
1491 QDataStream out(&data, QIODeviceBase::WriteOnly);
1496template <
typename T>
1499 std::chrono::seconds expiration,
1502 return Memcached::add<T>(key, value, expiration.count(), returnType);
1507 const QByteArray &value,
1508 std::chrono::seconds expiration,
1514template <
typename T>
1522 QDataStream out(&data, QIODeviceBase::WriteOnly);
1527template <
typename T>
1531 std::chrono::seconds expiration,
1534 return Memcached::addByKey<T>(groupKey, key, value, expiration.count(), returnType);
1538 const QByteArray &value,
1539 std::chrono::seconds expiration,
1545template <
typename T>
1552 QDataStream out(&data, QIODeviceBase::WriteOnly);
1557template <
typename T>
1560 std::chrono::seconds expiration,
1563 return Memcached::replace<T>(key, value, expiration.count(), returnType);
1568 const QByteArray &value,
1569 std::chrono::seconds expiration,
1575template <
typename T>
1583 QDataStream out(&data, QIODeviceBase::WriteOnly);
1588template <
typename T>
1592 std::chrono::seconds expiration,
1595 return Memcached::replaceByKey<T>(groupKey, key, value, expiration.count(), returnType);
1601 std::chrono::seconds expiration,
1606 key, offset, initial, expiration.count(), value, returnType);
1613 std::chrono::seconds expiration,
1618 groupKey, key, offset, initial, expiration.count(), value, returnType);
1624 std::chrono::seconds expiration,
1629 key, offset, initial, expiration.count(), value, returnType);
1636 std::chrono::seconds expiration,
1641 groupKey, key, offset, initial, expiration.count(), value, returnType);
1644template <
typename T>
1649 if (!ba.isEmpty()) {
1650 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1656template <
typename T>
1664 if (!ba.isEmpty()) {
1665 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1672 const QByteArray &value,
1673 std::chrono::seconds expiration,
1680template <
typename T>
1688 QDataStream out(&data, QIODeviceBase::WriteOnly);
1693template <
typename T>
1696 std::chrono::seconds expiration,
1700 return Memcached::cas<T>(key, value, expiration.count(),
cas, returnType);
1705 const QByteArray &value,
1706 std::chrono::seconds expiration,
1713template <
typename T>
1722 QDataStream out(&data, QIODeviceBase::WriteOnly);
1727template <
typename T>
1731 std::chrono::seconds expiration,
1735 return Memcached::casByKey<T>(groupKey, key, value, expiration.count(),
cas, returnType);
1743template <
typename T>
1745 QHash<QByteArray, uint64_t> *casValues,
1748 QHash<QByteArray, T> hash;
1749 QHash<QByteArray, QByteArray> _data =
Memcached::mget(keys, casValues, returnType);
1750 if (!_data.empty()) {
1751 auto i = _data.constBegin();
1752 while (i != _data.constEnd()) {
1754 QDataStream in(i.value());
1756 hash.insert(i.key(), retVal);
1763template <
typename T>
1765 const QByteArrayList &keys,
1766 QHash<QByteArray, uint64_t> *casValues,
1769 QHash<QByteArray, T> hash;
1770 QHash<QByteArray, QByteArray> _data =
1772 if (!_data.empty()) {
1773 auto i = _data.constBegin();
1774 while (i != _data.constEnd()) {
1776 QDataStream in(i.value());
1778 hash.insert(i.key(), retVal);
1786 std::chrono::seconds expiration,
1794 std::chrono::seconds expiration,
The Cutelyst Application.
Cutelyst Memcached plugin.
static QByteArray getByKey(QByteArrayView groupKey, QByteArrayView key, uint64_t *cas=nullptr, MemcachedReturnType *returnType=nullptr)
static bool touchByKey(QByteArrayView groupKey, QByteArrayView key, time_t expiration, MemcachedReturnType *returnType=nullptr)
@ MemoryAllocationFailure
static QHash< QByteArray, QByteArray > mgetByKey(QByteArrayView groupKey, const QByteArrayList &keys, QHash< QByteArray, uint64_t > *casValues=nullptr, MemcachedReturnType *returnType=nullptr)
static const std::chrono::seconds expirationNotAddDuration
static bool cas(QByteArrayView key, const QByteArray &value, time_t expiration, uint64_t cas, MemcachedReturnType *returnType=nullptr)
static bool flush(time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool set(QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool incrementWithInitialByKey(QByteArrayView groupKey, QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static bool add(QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static const time_t expirationNotAdd
static QByteArray get(QByteArrayView key, uint64_t *cas=nullptr, MemcachedReturnType *returnType=nullptr)
static bool replace(QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool casByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, uint64_t cas, MemcachedReturnType *returnType=nullptr)
static bool decrementWithInitialByKey(QByteArrayView groupKey, QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static bool decrementWithInitial(QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static bool touch(QByteArrayView key, time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool incrementWithInitial(QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
static bool addByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static bool setByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
static QHash< QByteArray, QByteArray > mget(const QByteArrayList &keys, QHash< QByteArray, uint64_t > *casValues=nullptr, MemcachedReturnType *returnType=nullptr)
static bool replaceByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
The Cutelyst namespace holds all public Cutelyst API.