7#include <Cutelyst/Plugins/memcached_export.h>
8#include <Cutelyst/plugin.h>
12#include <QVersionNumber>
17class MemcachedPrivate;
216 MemoryAllocationFailure,
248 ServerTemporaryDisabled,
249 ServerMemoryAllocationFailure,
260 void setDefaultConfig(
const QVariantMap &defaultConfig);
274 static bool set(QByteArrayView key,
275 const QByteArray &value,
277 ReturnType *returnType =
nullptr);
283 inline static bool set(QByteArrayView key,
284 const QByteArray &value,
285 std::chrono::seconds expiration,
286 ReturnType *returnType =
nullptr);
302 template <
typename T>
303 static bool set(QByteArrayView key,
306 ReturnType *returnType =
nullptr);
312 template <
typename T>
313 static bool set(QByteArrayView key,
315 std::chrono::seconds expiration,
316 ReturnType *returnType =
nullptr);
334 static bool setByKey(QByteArrayView groupKey,
336 const QByteArray &value,
338 ReturnType *returnType =
nullptr);
344 inline static bool setByKey(QByteArrayView groupKey,
346 const QByteArray &value,
347 std::chrono::seconds expiration,
348 ReturnType *returnType =
nullptr);
367 template <
typename T>
368 static bool setByKey(QByteArrayView groupKey,
372 ReturnType *returnType =
nullptr);
378 template <
typename T>
379 static bool setByKey(QByteArrayView groupKey,
382 std::chrono::seconds expiration,
383 ReturnType *returnType =
nullptr);
400 static bool add(QByteArrayView key,
401 const QByteArray &value,
403 ReturnType *returnType =
nullptr);
409 inline static bool add(QByteArrayView key,
410 const QByteArray &value,
411 std::chrono::seconds expiration,
412 ReturnType *returnType =
nullptr);
432 template <
typename T>
433 static bool add(QByteArrayView key,
436 ReturnType *returnType =
nullptr);
442 template <
typename T>
443 static bool add(QByteArrayView key,
445 std::chrono::seconds expiration,
446 ReturnType *returnType =
nullptr);
467 static bool addByKey(QByteArrayView groupKey,
469 const QByteArray &value,
471 ReturnType *returnType =
nullptr);
477 inline static bool addByKey(QByteArrayView groupKey,
479 const QByteArray &value,
480 std::chrono::seconds expiration,
481 ReturnType *returnType =
nullptr);
504 template <
typename T>
505 static bool addByKey(QByteArrayView groupKey,
509 ReturnType *returnType =
nullptr);
515 template <
typename T>
516 static bool addByKey(QByteArrayView groupKey,
519 std::chrono::seconds expiration,
520 ReturnType *returnType =
nullptr);
537 static bool replace(QByteArrayView key,
538 const QByteArray &value,
540 ReturnType *returnType =
nullptr);
546 inline static bool replace(QByteArrayView key,
547 const QByteArray &value,
548 std::chrono::seconds expiration,
549 ReturnType *returnType =
nullptr);
568 template <
typename T>
569 static bool replace(QByteArrayView key,
572 ReturnType *returnType =
nullptr);
578 template <
typename T>
579 static bool replace(QByteArrayView key,
581 std::chrono::seconds expiration,
582 ReturnType *returnType =
nullptr);
603 static bool replaceByKey(QByteArrayView groupKey,
605 const QByteArray &value,
607 ReturnType *returnType =
nullptr);
613 inline static bool replaceByKey(QByteArrayView groupKey,
615 const QByteArray &value,
616 std::chrono::seconds expiration,
617 ReturnType *returnType =
nullptr);
640 template <
typename T>
641 static bool replaceByKey(QByteArrayView groupKey,
645 ReturnType *returnType =
nullptr);
651 template <
typename T>
652 static bool replaceByKey(QByteArrayView groupKey,
655 std::chrono::seconds expiration,
656 ReturnType *returnType =
nullptr);
676 get(QByteArrayView key, uint64_t *cas =
nullptr, ReturnType *returnType =
nullptr);
708 template <
typename T>
709 static T get(QByteArrayView key, uint64_t *cas =
nullptr, ReturnType *returnType =
nullptr);
731 static QByteArray getByKey(QByteArrayView groupKey,
733 uint64_t *cas =
nullptr,
734 ReturnType *returnType =
nullptr);
771 template <
typename T>
772 static T getByKey(QByteArrayView groupKey,
774 uint64_t *cas =
nullptr,
775 ReturnType *returnType =
nullptr);
785 static bool remove(QByteArrayView key, ReturnType *returnType =
nullptr);
800 removeByKey(QByteArrayView groupKey, QByteArrayView key, ReturnType *returnType =
nullptr);
809 static bool exist(QByteArrayView key, ReturnType *returnType =
nullptr);
823 existByKey(QByteArrayView groupKey, QByteArrayView key, ReturnType *returnType =
nullptr);
856 static bool increment(QByteArrayView key,
858 uint64_t *value =
nullptr,
879 static bool incrementByKey(QByteArrayView groupKey,
882 uint64_t *value =
nullptr,
909 static bool incrementWithInitial(QByteArrayView key,
913 uint64_t *value =
nullptr,
920 inline static bool incrementWithInitial(QByteArrayView key,
923 std::chrono::seconds expiration,
924 uint64_t *value =
nullptr,
956 static bool incrementWithInitialByKey(QByteArrayView groupKey,
961 uint64_t *value =
nullptr,
968 inline static bool incrementWithInitialByKey(QByteArrayView groupKey,
972 std::chrono::seconds expiration,
973 uint64_t *value =
nullptr,
991 static bool decrement(QByteArrayView key,
993 uint64_t *value =
nullptr,
1014 static bool decrementByKey(QByteArrayView groupKey,
1017 uint64_t *value =
nullptr,
1044 static bool decrementWithInitial(QByteArrayView key,
1048 uint64_t *value =
nullptr,
1055 inline static bool decrementWithInitial(QByteArrayView key,
1058 std::chrono::seconds expiration,
1059 uint64_t *value =
nullptr,
1091 static bool decrementWithInitialByKey(QByteArrayView groupKey,
1096 uint64_t *value =
nullptr,
1103 inline static bool decrementWithInitialByKey(QByteArrayView groupKey,
1107 std::chrono::seconds expiration,
1108 uint64_t *value =
nullptr,
1123 static bool cas(QByteArrayView key,
1124 const QByteArray &value,
1133 inline static bool cas(QByteArrayView key,
1134 const QByteArray &value,
1135 std::chrono::seconds expiration,
1153 template <
typename T>
1154 static bool cas(QByteArrayView key,
1164 template <
typename T>
1165 static bool cas(QByteArrayView key,
1167 std::chrono::seconds expiration,
1189 static bool casByKey(QByteArrayView groupKey,
1191 const QByteArray &value,
1200 inline static bool casByKey(QByteArrayView groupKey,
1202 const QByteArray &value,
1203 std::chrono::seconds expiration,
1227 template <
typename T>
1228 static bool casByKey(QByteArrayView groupKey,
1239 template <
typename T>
1240 static bool casByKey(QByteArrayView groupKey,
1243 std::chrono::seconds expiration,
1255 static bool flushBuffers(
ReturnType *returnType =
nullptr);
1268 static bool flush(time_t expiration,
ReturnType *returnType =
nullptr);
1274 inline static bool flush(std::chrono::seconds expiration,
ReturnType *returnType =
nullptr);
1289 static QHash<QByteArray, QByteArray> mget(
const QByteArrayList &keys,
1290 QHash<QByteArray, uint64_t> *casValues =
nullptr,
1308 template <
typename T>
1309 static QHash<QByteArray, T> mget(
const QByteArrayList &keys,
1310 QHash<QByteArray, uint64_t> *casValues =
nullptr,
1332 static QHash<QByteArray, QByteArray> mgetByKey(QByteArrayView groupKey,
1333 const QByteArrayList &keys,
1334 QHash<QByteArray, uint64_t> *casValues =
nullptr,
1358 template <
typename T>
1359 static QHash<QByteArray, T> mgetByKey(QByteArrayView groupKey,
1360 const QByteArrayList &keys,
1361 QHash<QByteArray, uint64_t> *casValues =
nullptr,
1373 static bool touch(QByteArrayView key, time_t expiration,
ReturnType *returnType =
nullptr);
1379 inline static bool touch(QByteArrayView key,
1380 std::chrono::seconds expiration,
1397 static bool touchByKey(QByteArrayView groupKey,
1406 inline static bool touchByKey(QByteArrayView groupKey,
1408 std::chrono::seconds expiration,
1419 static QVersionNumber libMemcachedVersion();
1428 const std::unique_ptr<MemcachedPrivate> d_ptr;
1432 const QByteArray &value,
1433 std::chrono::seconds expiration,
1436 return Memcached::set(key, value, expiration.count(), returnType);
1439template <
typename T>
1443 QDataStream out(&data, QIODeviceBase::WriteOnly);
1448template <
typename T>
1451 std::chrono::seconds expiration,
1454 return Memcached::set<T>(key, value, expiration.count(), returnType);
1459 const QByteArray &value,
1460 std::chrono::seconds expiration,
1466template <
typename T>
1474 QDataStream out(&data, QIODeviceBase::WriteOnly);
1479template <
typename T>
1483 std::chrono::seconds expiration,
1486 return Memcached::setByKey<T>(groupKey, key, value, expiration.count(), returnType);
1490 const QByteArray &value,
1491 std::chrono::seconds expiration,
1494 return Memcached::add(key, value, expiration.count(), returnType);
1497template <
typename T>
1501 QDataStream out(&data, QIODeviceBase::WriteOnly);
1506template <
typename T>
1509 std::chrono::seconds expiration,
1512 return Memcached::add<T>(key, value, expiration.count(), returnType);
1517 const QByteArray &value,
1518 std::chrono::seconds expiration,
1524template <
typename T>
1532 QDataStream out(&data, QIODeviceBase::WriteOnly);
1537template <
typename T>
1541 std::chrono::seconds expiration,
1544 return Memcached::addByKey<T>(groupKey, key, value, expiration.count(), returnType);
1548 const QByteArray &value,
1549 std::chrono::seconds expiration,
1555template <
typename T>
1562 QDataStream out(&data, QIODeviceBase::WriteOnly);
1567template <
typename T>
1570 std::chrono::seconds expiration,
1573 return Memcached::replace<T>(key, value, expiration.count(), returnType);
1578 const QByteArray &value,
1579 std::chrono::seconds expiration,
1585template <
typename T>
1593 QDataStream out(&data, QIODeviceBase::WriteOnly);
1598template <
typename T>
1602 std::chrono::seconds expiration,
1605 return Memcached::replaceByKey<T>(groupKey, key, value, expiration.count(), returnType);
1611 std::chrono::seconds expiration,
1616 key, offset, initial, expiration.count(), value, returnType);
1623 std::chrono::seconds expiration,
1628 groupKey, key, offset, initial, expiration.count(), value, returnType);
1634 std::chrono::seconds expiration,
1639 key, offset, initial, expiration.count(), value, returnType);
1646 std::chrono::seconds expiration,
1651 groupKey, key, offset, initial, expiration.count(), value, returnType);
1654template <
typename T>
1659 if (!ba.isEmpty()) {
1660 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1666template <
typename T>
1674 if (!ba.isEmpty()) {
1675 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1682 const QByteArray &value,
1683 std::chrono::seconds expiration,
1690template <
typename T>
1698 QDataStream out(&data, QIODeviceBase::WriteOnly);
1703template <
typename T>
1706 std::chrono::seconds expiration,
1710 return Memcached::cas<T>(key, value, expiration.count(),
cas, returnType);
1715 const QByteArray &value,
1716 std::chrono::seconds expiration,
1723template <
typename T>
1732 QDataStream out(&data, QIODeviceBase::WriteOnly);
1737template <
typename T>
1741 std::chrono::seconds expiration,
1745 return Memcached::casByKey<T>(groupKey, key, value, expiration.count(),
cas, returnType);
1753template <
typename T>
1755 QHash<QByteArray, uint64_t> *casValues,
1758 QHash<QByteArray, T> hash;
1759 QHash<QByteArray, QByteArray> _data =
Memcached::mget(keys, casValues, returnType);
1760 if (!_data.empty()) {
1761 auto i = _data.constBegin();
1762 while (i != _data.constEnd()) {
1764 QDataStream in(i.value());
1766 hash.insert(i.key(), retVal);
1773template <
typename T>
1775 const QByteArrayList &keys,
1776 QHash<QByteArray, uint64_t> *casValues,
1779 QHash<QByteArray, T> hash;
1780 QHash<QByteArray, QByteArray> _data =
1782 if (!_data.empty()) {
1783 auto i = _data.constBegin();
1784 while (i != _data.constEnd()) {
1786 QDataStream in(i.value());
1788 hash.insert(i.key(), retVal);
1803 std::chrono::seconds expiration,
The Cutelyst application.
Cutelyst Memcached plugin.
static bool touch(QByteArrayView key, time_t expiration, ReturnType *returnType=nullptr)
static bool flush(time_t expiration, ReturnType *returnType=nullptr)
static bool touchByKey(QByteArrayView groupKey, QByteArrayView key, time_t expiration, ReturnType *returnType=nullptr)
static const std::chrono::seconds expirationNotAddDuration
static bool decrementWithInitial(QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, ReturnType *returnType=nullptr)
static bool incrementWithInitial(QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, ReturnType *returnType=nullptr)
static QHash< QByteArray, QByteArray > mgetByKey(QByteArrayView groupKey, const QByteArrayList &keys, QHash< QByteArray, uint64_t > *casValues=nullptr, ReturnType *returnType=nullptr)
static bool cas(QByteArrayView key, const QByteArray &value, time_t expiration, uint64_t cas, ReturnType *returnType=nullptr)
static bool replace(QByteArrayView key, const QByteArray &value, time_t expiration, ReturnType *returnType=nullptr)
static bool set(QByteArrayView key, const QByteArray &value, time_t expiration, ReturnType *returnType=nullptr)
static bool replaceByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, ReturnType *returnType=nullptr)
static bool casByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, uint64_t cas, ReturnType *returnType=nullptr)
static QHash< QByteArray, QByteArray > mget(const QByteArrayList &keys, QHash< QByteArray, uint64_t > *casValues=nullptr, ReturnType *returnType=nullptr)
static bool decrementWithInitialByKey(QByteArrayView groupKey, QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, ReturnType *returnType=nullptr)
static QByteArray getByKey(QByteArrayView groupKey, QByteArrayView key, uint64_t *cas=nullptr, ReturnType *returnType=nullptr)
static const time_t expirationNotAdd
static bool addByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, ReturnType *returnType=nullptr)
static bool incrementWithInitialByKey(QByteArrayView groupKey, QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, ReturnType *returnType=nullptr)
static bool setByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, ReturnType *returnType=nullptr)
static QByteArray get(QByteArrayView key, uint64_t *cas=nullptr, ReturnType *returnType=nullptr)
static bool add(QByteArrayView key, const QByteArray &value, time_t expiration, ReturnType *returnType=nullptr)
Base class for Cutelyst Plugins.
The Cutelyst namespace holds all public Cutelyst API.