cutelyst 4.0.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
memcached.h
1/*
2 * SPDX-FileCopyrightText: (C) 2017-2022 Matthias Fehring <mf@huessenbergnetz.de>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#pragma once
6
7#include <Cutelyst/cutelyst_global.h>
8#include <Cutelyst/plugin.h>
9#include <chrono>
10
11#include <QDataStream>
12#include <QVersionNumber>
13
14namespace Cutelyst {
15
16class Context;
17class MemcachedPrivate;
18
156class CUTELYST_PLUGIN_MEMCACHED_EXPORT Memcached // clazy:exclude=ctor-missing-parent-argument
157 : public Plugin
158{
159 Q_OBJECT
160 Q_DECLARE_PRIVATE(Memcached) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
161 Q_DISABLE_COPY(Memcached)
162public:
166 Memcached(Application *parent);
167
171 ~Memcached() override;
172
183 UnknownReadFailure,
197 SomeErrors,
205 FetchNotFinished,
210 InvalidHostProtocol,
214 UnknownStatKey,
222 ParseError,
226 InProgress,
227 ServerTemporaryDisabled,
228 ServerMemoryAllocationFailure,
229 MaximumReturn,
230 PluginNotRegisterd
232 };
233 Q_ENUM(MemcachedReturnType)
234
235
239 void setDefaultConfig(const QVariantMap &defaultConfig);
240
253 static bool set(QByteArrayView key,
254 const QByteArray &value,
255 time_t expiration,
256 MemcachedReturnType *returnType = nullptr);
257
262 inline static bool set(QByteArrayView key,
263 const QByteArray &value,
264 std::chrono::seconds expiration,
265 MemcachedReturnType *returnType = nullptr);
266
281 template <typename T>
282 static bool set(QByteArrayView key,
283 const T &value,
284 time_t expiration,
285 MemcachedReturnType *returnType = nullptr);
286
291 template <typename T>
292 static bool set(QByteArrayView key,
293 const T &value,
294 std::chrono::seconds expiration,
295 MemcachedReturnType *returnType = nullptr);
296
313 static bool setByKey(QByteArrayView groupKey,
314 QByteArrayView key,
315 const QByteArray &value,
316 time_t expiration,
317 MemcachedReturnType *returnType = nullptr);
318
323 inline static bool setByKey(QByteArrayView groupKey,
324 QByteArrayView key,
325 const QByteArray &value,
326 std::chrono::seconds expiration,
327 MemcachedReturnType *returnType = nullptr);
328
346 template <typename T>
347 static bool setByKey(QByteArrayView groupKey,
348 QByteArrayView key,
349 const T &value,
350 time_t expiration,
351 MemcachedReturnType *returnType = nullptr);
352
357 template <typename T>
358 static bool setByKey(QByteArrayView groupKey,
359 QByteArrayView key,
360 const T &value,
361 std::chrono::seconds expiration,
362 MemcachedReturnType *returnType = nullptr);
363
379 static bool add(QByteArrayView key,
380 const QByteArray &value,
381 time_t expiration,
382 MemcachedReturnType *returnType = nullptr);
383
388 inline static bool add(QByteArrayView key,
389 const QByteArray &value,
390 std::chrono::seconds expiration,
391 MemcachedReturnType *returnType = nullptr);
392
411 template <typename T>
412 static bool add(QByteArrayView key,
413 const T &value,
414 time_t expiration,
415 MemcachedReturnType *returnType = nullptr);
416
421 template <typename T>
422 static bool add(QByteArrayView key,
423 const T &value,
424 std::chrono::seconds expiration,
425 MemcachedReturnType *returnType = nullptr);
426
446 static bool addByKey(QByteArrayView groupKey,
447 QByteArrayView key,
448 const QByteArray &value,
449 time_t expiration,
450 MemcachedReturnType *returnType = nullptr);
451
456 inline static bool addByKey(QByteArrayView groupKey,
457 QByteArrayView key,
458 const QByteArray &value,
459 std::chrono::seconds expiration,
460 MemcachedReturnType *returnType = nullptr);
461
483 template <typename T>
484 static bool addByKey(QByteArrayView groupKey,
485 QByteArrayView key,
486 const T &value,
487 time_t expiration,
488 MemcachedReturnType *returnType = nullptr);
489
494 template <typename T>
495 static bool addByKey(QByteArrayView groupKey,
496 QByteArrayView key,
497 const T &value,
498 std::chrono::seconds expiration,
499 MemcachedReturnType *returnType = nullptr);
500
516 static bool replace(QByteArrayView key,
517 const QByteArray &value,
518 time_t expiration,
519 MemcachedReturnType *returnType = nullptr);
520
525 inline static bool replace(QByteArrayView key,
526 const QByteArray &value,
527 std::chrono::seconds expiration,
528 MemcachedReturnType *returnType = nullptr);
529
547 template <typename T>
548 static bool replace(QByteArrayView key,
549 const T &value,
550 time_t expiration,
551 MemcachedReturnType *returnType = nullptr);
552
557 template <typename T>
558 static bool replace(QByteArrayView key,
559 const T &value,
560 std::chrono::seconds expiration,
561 MemcachedReturnType *returnType = nullptr);
562
582 static bool replaceByKey(QByteArrayView groupKey,
583 QByteArrayView key,
584 const QByteArray &value,
585 time_t expiration,
586 MemcachedReturnType *returnType = nullptr);
587
592 inline static bool replaceByKey(QByteArrayView groupKey,
593 QByteArrayView key,
594 const QByteArray &value,
595 std::chrono::seconds expiration,
596 MemcachedReturnType *returnType = nullptr);
597
619 template <typename T>
620 static bool replaceByKey(QByteArrayView groupKey,
621 QByteArrayView key,
622 const T &value,
623 time_t expiration,
624 MemcachedReturnType *returnType = nullptr);
625
630 template <typename T>
631 static bool replaceByKey(QByteArrayView groupKey,
632 QByteArrayView key,
633 const T &value,
634 std::chrono::seconds expiration,
635 MemcachedReturnType *returnType = nullptr);
636
654 static QByteArray
655 get(QByteArrayView key, uint64_t *cas = nullptr, MemcachedReturnType *returnType = nullptr);
656
687 template <typename T>
688 static T
689 get(QByteArrayView key, uint64_t *cas = nullptr, MemcachedReturnType *returnType = nullptr);
690
711 static QByteArray getByKey(QByteArrayView groupKey,
712 QByteArrayView key,
713 uint64_t *cas = nullptr,
714 MemcachedReturnType *returnType = nullptr);
715
751 template <typename T>
752 static T getByKey(QByteArrayView groupKey,
753 QByteArrayView key,
754 uint64_t *cas = nullptr,
755 MemcachedReturnType *returnType = nullptr);
756
765 static bool remove(QByteArrayView key, MemcachedReturnType *returnType = nullptr);
766
779 static bool removeByKey(QByteArrayView groupKey,
780 QByteArrayView key,
781 MemcachedReturnType *returnType = nullptr);
782
790 static bool exist(QByteArrayView key, MemcachedReturnType *returnType = nullptr);
791
803 static bool existByKey(QByteArrayView groupKey,
804 QByteArrayView key,
805 MemcachedReturnType *returnType = nullptr);
806
812 static const time_t expirationNotAdd;
813
821 static const std::chrono::seconds expirationNotAddDuration;
822
838 static bool increment(QByteArrayView key,
839 uint32_t offset,
840 uint64_t *value = nullptr,
841 MemcachedReturnType *returnType = nullptr);
842
861 static bool incrementByKey(QByteArrayView groupKey,
862 QByteArrayView key,
863 uint64_t offset,
864 uint64_t *value = nullptr,
865 MemcachedReturnType *returnType = nullptr);
866
891 static bool incrementWithInitial(QByteArrayView key,
892 uint64_t offset,
893 uint64_t initial,
894 time_t expiration,
895 uint64_t *value = nullptr,
896 MemcachedReturnType *returnType = nullptr);
897
902 inline static bool incrementWithInitial(QByteArrayView key,
903 uint64_t offset,
904 uint64_t initial,
905 std::chrono::seconds expiration,
906 uint64_t *value = nullptr,
907 MemcachedReturnType *returnType = nullptr);
908
938 static bool incrementWithInitialByKey(QByteArrayView groupKey,
939 QByteArrayView key,
940 uint64_t offset,
941 uint64_t initial,
942 time_t expiration,
943 uint64_t *value = nullptr,
944 MemcachedReturnType *returnType = nullptr);
945
950 inline static bool incrementWithInitialByKey(QByteArrayView groupKey,
951 QByteArrayView key,
952 uint64_t offset,
953 uint64_t initial,
954 std::chrono::seconds expiration,
955 uint64_t *value = nullptr,
956 MemcachedReturnType *returnType = nullptr);
957
973 static bool decrement(QByteArrayView key,
974 uint32_t offset,
975 uint64_t *value = nullptr,
976 MemcachedReturnType *returnType = nullptr);
977
996 static bool decrementByKey(QByteArrayView groupKey,
997 QByteArrayView key,
998 uint64_t offset,
999 uint64_t *value = nullptr,
1000 MemcachedReturnType *returnType = nullptr);
1001
1026 static bool decrementWithInitial(QByteArrayView key,
1027 uint64_t offset,
1028 uint64_t initial,
1029 time_t expiration,
1030 uint64_t *value = nullptr,
1031 MemcachedReturnType *returnType = nullptr);
1032
1037 inline static bool decrementWithInitial(QByteArrayView key,
1038 uint64_t offset,
1039 uint64_t initial,
1040 std::chrono::seconds expiration,
1041 uint64_t *value = nullptr,
1042 MemcachedReturnType *returnType = nullptr);
1043
1073 static bool decrementWithInitialByKey(QByteArrayView groupKey,
1074 QByteArrayView key,
1075 uint64_t offset,
1076 uint64_t initial,
1077 time_t expiration,
1078 uint64_t *value = nullptr,
1079 MemcachedReturnType *returnType = nullptr);
1080
1085 inline static bool decrementWithInitialByKey(QByteArrayView groupKey,
1086 QByteArrayView key,
1087 uint64_t offset,
1088 uint64_t initial,
1089 std::chrono::seconds expiration,
1090 uint64_t *value = nullptr,
1091 MemcachedReturnType *returnType = nullptr);
1092
1105 static bool cas(QByteArrayView key,
1106 const QByteArray &value,
1107 time_t expiration,
1108 uint64_t cas,
1109 MemcachedReturnType *returnType = nullptr);
1110
1115 inline static bool cas(QByteArrayView key,
1116 const QByteArray &value,
1117 std::chrono::seconds expiration,
1118 uint64_t cas,
1119 MemcachedReturnType *returnType = nullptr);
1120
1135 template <typename T>
1136 static bool cas(QByteArrayView key,
1137 const T &value,
1138 time_t expiration,
1139 uint64_t cas,
1140 MemcachedReturnType *returnType = nullptr);
1141
1146 template <typename T>
1147 static bool cas(QByteArrayView key,
1148 const T &value,
1149 std::chrono::seconds expiration,
1150 uint64_t cas,
1151 MemcachedReturnType *returnType = nullptr);
1152
1171 static bool casByKey(QByteArrayView groupKey,
1172 QByteArrayView key,
1173 const QByteArray &value,
1174 time_t expiration,
1175 uint64_t cas,
1176 MemcachedReturnType *returnType = nullptr);
1177
1182 inline static bool casByKey(QByteArrayView groupKey,
1183 QByteArrayView key,
1184 const QByteArray &value,
1185 std::chrono::seconds expiration,
1186 uint64_t cas,
1187 MemcachedReturnType *returnType = nullptr);
1188
1209 template <typename T>
1210 static bool casByKey(QByteArrayView groupKey,
1211 QByteArrayView key,
1212 const T &value,
1213 time_t expiration,
1214 uint64_t cas,
1215 MemcachedReturnType *returnType = nullptr);
1216
1221 template <typename T>
1222 static bool casByKey(QByteArrayView groupKey,
1223 QByteArrayView key,
1224 const T &value,
1225 std::chrono::seconds expiration,
1226 uint64_t cas,
1227 MemcachedReturnType *returnType = nullptr);
1228
1237 static bool flushBuffers(MemcachedReturnType *returnType = nullptr);
1238
1250 static bool flush(time_t expiration, MemcachedReturnType *returnType = nullptr);
1251
1256 inline static bool flush(std::chrono::seconds expiration,
1257 MemcachedReturnType *returnType = nullptr);
1258
1272 static QHash<QByteArray, QByteArray> mget(const QByteArrayList &keys,
1273 QHash<QByteArray, uint64_t> *casValues = nullptr,
1274 MemcachedReturnType *returnType = nullptr);
1275
1291 template <typename T>
1292 static QHash<QByteArray, T> mget(const QByteArrayList &keys,
1293 QHash<QByteArray, uint64_t> *casValues = nullptr,
1294 MemcachedReturnType *returnType = nullptr);
1295
1315 static QHash<QByteArray, QByteArray> mgetByKey(QByteArrayView groupKey,
1316 const QByteArrayList &keys,
1317 QHash<QByteArray, uint64_t> *casValues = nullptr,
1318 MemcachedReturnType *returnType = nullptr);
1319
1341 template <typename T>
1342 static QHash<QByteArray, T> mgetByKey(QByteArrayView groupKey,
1343 const QByteArrayList &keys,
1344 QHash<QByteArray, uint64_t> *casValues = nullptr,
1345 MemcachedReturnType *returnType = nullptr);
1346
1356 static bool
1357 touch(QByteArrayView key, time_t expiration, MemcachedReturnType *returnType = nullptr);
1358
1363 inline static bool touch(QByteArrayView key,
1364 std::chrono::seconds expiration,
1365 MemcachedReturnType *returnType = nullptr);
1366
1381 static bool touchByKey(QByteArrayView groupKey,
1382 QByteArrayView key,
1383 time_t expiration,
1384 MemcachedReturnType *returnType = nullptr);
1385
1390 inline static bool touchByKey(QByteArrayView groupKey,
1391 QByteArrayView key,
1392 std::chrono::seconds expiration,
1393 MemcachedReturnType *returnType = nullptr);
1394
1398 static QString errorString(Context *c, MemcachedReturnType rt);
1399
1403 static QVersionNumber libMemcachedVersion();
1404
1405protected:
1409 bool setup(Application *app) override;
1410
1411private:
1412 const std::unique_ptr<MemcachedPrivate> d_ptr;
1413};
1414
1415inline bool Memcached::set(QByteArrayView key,
1416 const QByteArray &value,
1417 std::chrono::seconds expiration,
1418 MemcachedReturnType *returnType)
1419{
1420 return Memcached::set(key, value, expiration.count(), returnType);
1421}
1422
1423template <typename T>
1424bool Memcached::set(QByteArrayView key,
1425 const T &value,
1426 time_t expiration,
1427 MemcachedReturnType *returnType)
1428{
1429 QByteArray data;
1430 QDataStream out(&data, QIODeviceBase::WriteOnly);
1431 out << value;
1432 return Memcached::set(key, data, expiration, returnType);
1433}
1434
1435template <typename T>
1436bool Memcached::set(QByteArrayView key,
1437 const T &value,
1438 std::chrono::seconds expiration,
1439 MemcachedReturnType *returnType)
1440{
1441 return Memcached::set<T>(key, value, expiration.count(), returnType);
1442}
1443
1444inline bool Memcached::setByKey(QByteArrayView groupKey,
1445 QByteArrayView key,
1446 const QByteArray &value,
1447 std::chrono::seconds expiration,
1448 MemcachedReturnType *returnType)
1449{
1450 return Memcached::setByKey(groupKey, key, value, expiration.count(), returnType);
1451}
1452
1453template <typename T>
1454bool Memcached::setByKey(QByteArrayView groupKey,
1455 QByteArrayView key,
1456 const T &value,
1457 time_t expiration,
1458 MemcachedReturnType *returnType)
1459{
1460 QByteArray data;
1461 QDataStream out(&data, QIODeviceBase::WriteOnly);
1462 out << value;
1463 return Memcached::setByKey(groupKey, key, data, expiration, returnType);
1464}
1465
1466template <typename T>
1467bool Memcached::setByKey(QByteArrayView groupKey,
1468 QByteArrayView key,
1469 const T &value,
1470 std::chrono::seconds expiration,
1471 MemcachedReturnType *returnType)
1472{
1473 return Memcached::setByKey<T>(groupKey, key, value, expiration.count(), returnType);
1474}
1475
1476inline bool Memcached::add(QByteArrayView key,
1477 const QByteArray &value,
1478 std::chrono::seconds expiration,
1479 MemcachedReturnType *returnType)
1480{
1481 return Memcached::add(key, value, expiration.count(), returnType);
1482}
1483
1484template <typename T>
1485bool Memcached::add(QByteArrayView key,
1486 const T &value,
1487 time_t expiration,
1488 MemcachedReturnType *returnType)
1489{
1490 QByteArray data;
1491 QDataStream out(&data, QIODeviceBase::WriteOnly);
1492 out << value;
1493 return Memcached::add(key, data, expiration, returnType);
1494}
1495
1496template <typename T>
1497bool Memcached::add(QByteArrayView key,
1498 const T &value,
1499 std::chrono::seconds expiration,
1500 MemcachedReturnType *returnType)
1501{
1502 return Memcached::add<T>(key, value, expiration.count(), returnType);
1503}
1504
1505inline bool Memcached::addByKey(QByteArrayView groupKey,
1506 QByteArrayView key,
1507 const QByteArray &value,
1508 std::chrono::seconds expiration,
1509 MemcachedReturnType *returnType)
1510{
1511 return Memcached::addByKey(groupKey, key, value, expiration.count(), returnType);
1512}
1513
1514template <typename T>
1515bool Memcached::addByKey(QByteArrayView groupKey,
1516 QByteArrayView key,
1517 const T &value,
1518 time_t expiration,
1519 MemcachedReturnType *returnType)
1520{
1521 QByteArray data;
1522 QDataStream out(&data, QIODeviceBase::WriteOnly);
1523 out << value;
1524 return Memcached::addByKey(groupKey, key, data, expiration, returnType);
1525}
1526
1527template <typename T>
1528bool Memcached::addByKey(QByteArrayView groupKey,
1529 QByteArrayView key,
1530 const T &value,
1531 std::chrono::seconds expiration,
1532 MemcachedReturnType *returnType)
1533{
1534 return Memcached::addByKey<T>(groupKey, key, value, expiration.count(), returnType);
1535}
1536
1537inline bool Memcached::replace(QByteArrayView key,
1538 const QByteArray &value,
1539 std::chrono::seconds expiration,
1540 MemcachedReturnType *returnType)
1541{
1542 return Memcached::replace(key, value, expiration.count(), returnType);
1543}
1544
1545template <typename T>
1546bool Memcached::replace(QByteArrayView key,
1547 const T &value,
1548 time_t expiration,
1549 MemcachedReturnType *returnType)
1550{
1551 QByteArray data;
1552 QDataStream out(&data, QIODeviceBase::WriteOnly);
1553 out << value;
1554 return Memcached::replace(key, data, expiration, returnType);
1555}
1556
1557template <typename T>
1558bool Memcached::replace(QByteArrayView key,
1559 const T &value,
1560 std::chrono::seconds expiration,
1561 MemcachedReturnType *returnType)
1562{
1563 return Memcached::replace<T>(key, value, expiration.count(), returnType);
1564}
1565
1566inline bool Memcached::replaceByKey(QByteArrayView groupKey,
1567 QByteArrayView key,
1568 const QByteArray &value,
1569 std::chrono::seconds expiration,
1570 MemcachedReturnType *returnType)
1571{
1572 return Memcached::replaceByKey(groupKey, key, value, expiration.count(), returnType);
1573}
1574
1575template <typename T>
1576bool Memcached::replaceByKey(QByteArrayView groupKey,
1577 QByteArrayView key,
1578 const T &value,
1579 time_t expiration,
1580 MemcachedReturnType *returnType)
1581{
1582 QByteArray data;
1583 QDataStream out(&data, QIODeviceBase::WriteOnly);
1584 out << value;
1585 return Memcached::replaceByKey(groupKey, key, data, expiration, returnType);
1586}
1587
1588template <typename T>
1589bool Memcached::replaceByKey(QByteArrayView groupKey,
1590 QByteArrayView key,
1591 const T &value,
1592 std::chrono::seconds expiration,
1593 MemcachedReturnType *returnType)
1594{
1595 return Memcached::replaceByKey<T>(groupKey, key, value, expiration.count(), returnType);
1596}
1597
1598inline bool Memcached::incrementWithInitial(QByteArrayView key,
1599 uint64_t offset,
1600 uint64_t initial,
1601 std::chrono::seconds expiration,
1602 uint64_t *value,
1603 MemcachedReturnType *returnType)
1604{
1606 key, offset, initial, expiration.count(), value, returnType);
1607}
1608
1609inline bool Memcached::incrementWithInitialByKey(QByteArrayView groupKey,
1610 QByteArrayView key,
1611 uint64_t offset,
1612 uint64_t initial,
1613 std::chrono::seconds expiration,
1614 uint64_t *value,
1615 MemcachedReturnType *returnType)
1616{
1618 groupKey, key, offset, initial, expiration.count(), value, returnType);
1619}
1620
1621inline bool Memcached::decrementWithInitial(QByteArrayView key,
1622 uint64_t offset,
1623 uint64_t initial,
1624 std::chrono::seconds expiration,
1625 uint64_t *value,
1626 MemcachedReturnType *returnType)
1627{
1629 key, offset, initial, expiration.count(), value, returnType);
1630}
1631
1632inline bool Memcached::decrementWithInitialByKey(QByteArrayView groupKey,
1633 QByteArrayView key,
1634 uint64_t offset,
1635 uint64_t initial,
1636 std::chrono::seconds expiration,
1637 uint64_t *value,
1638 MemcachedReturnType *returnType)
1639{
1641 groupKey, key, offset, initial, expiration.count(), value, returnType);
1642}
1643
1644template <typename T>
1645T Memcached::get(QByteArrayView key, uint64_t *cas, MemcachedReturnType *returnType)
1646{
1647 T retVal;
1648 QByteArray ba = Memcached::get(key, cas, returnType);
1649 if (!ba.isEmpty()) {
1650 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1651 in >> retVal;
1652 }
1653 return retVal;
1654}
1655
1656template <typename T>
1657T Memcached::getByKey(QByteArrayView groupKey,
1658 QByteArrayView key,
1659 uint64_t *cas,
1660 MemcachedReturnType *returnType)
1661{
1662 T retVal;
1663 QByteArray ba = Memcached::getByKey(groupKey, key, cas, returnType);
1664 if (!ba.isEmpty()) {
1665 QDataStream in(&ba, QIODeviceBase::ReadOnly);
1666 in >> retVal;
1667 }
1668 return retVal;
1669}
1670
1671inline bool Memcached::cas(QByteArrayView key,
1672 const QByteArray &value,
1673 std::chrono::seconds expiration,
1674 uint64_t cas,
1675 MemcachedReturnType *returnType)
1676{
1677 return Memcached::cas(key, value, expiration.count(), cas, returnType);
1678}
1679
1680template <typename T>
1681bool Memcached::cas(QByteArrayView key,
1682 const T &value,
1683 time_t expiration,
1684 uint64_t cas,
1685 MemcachedReturnType *returnType)
1686{
1687 QByteArray data;
1688 QDataStream out(&data, QIODeviceBase::WriteOnly);
1689 out << value;
1690 return Memcached::cas(key, data, expiration, cas, returnType);
1691}
1692
1693template <typename T>
1694bool Memcached::cas(QByteArrayView key,
1695 const T &value,
1696 std::chrono::seconds expiration,
1697 uint64_t cas,
1698 MemcachedReturnType *returnType)
1699{
1700 return Memcached::cas<T>(key, value, expiration.count(), cas, returnType);
1701}
1702
1703inline bool Memcached::casByKey(QByteArrayView groupKey,
1704 QByteArrayView key,
1705 const QByteArray &value,
1706 std::chrono::seconds expiration,
1707 uint64_t cas,
1708 MemcachedReturnType *returnType)
1709{
1710 return Memcached::casByKey(groupKey, key, value, expiration.count(), cas, returnType);
1711}
1712
1713template <typename T>
1714bool Memcached::casByKey(QByteArrayView groupKey,
1715 QByteArrayView key,
1716 const T &value,
1717 time_t expiration,
1718 uint64_t cas,
1719 MemcachedReturnType *returnType)
1720{
1721 QByteArray data;
1722 QDataStream out(&data, QIODeviceBase::WriteOnly);
1723 out << value;
1724 return Memcached::casByKey(groupKey, key, data, expiration, cas, returnType);
1725}
1726
1727template <typename T>
1728bool Memcached::casByKey(QByteArrayView groupKey,
1729 QByteArrayView key,
1730 const T &value,
1731 std::chrono::seconds expiration,
1732 uint64_t cas,
1733 MemcachedReturnType *returnType)
1734{
1735 return Memcached::casByKey<T>(groupKey, key, value, expiration.count(), cas, returnType);
1736}
1737
1738inline bool Memcached::flush(std::chrono::seconds expiration, MemcachedReturnType *returnType)
1739{
1740 return Memcached::flush(expiration.count(), returnType);
1741}
1742
1743template <typename T>
1744QHash<QByteArray, T> Memcached::mget(const QByteArrayList &keys,
1745 QHash<QByteArray, uint64_t> *casValues,
1746 MemcachedReturnType *returnType)
1747{
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()) {
1753 T retVal;
1754 QDataStream in(i.value());
1755 in >> retVal;
1756 hash.insert(i.key(), retVal);
1757 ++i;
1758 }
1759 }
1760 return hash;
1761}
1762
1763template <typename T>
1764QHash<QByteArray, T> Memcached::mgetByKey(QByteArrayView groupKey,
1765 const QByteArrayList &keys,
1766 QHash<QByteArray, uint64_t> *casValues,
1767 MemcachedReturnType *returnType)
1768{
1769 QHash<QByteArray, T> hash;
1770 QHash<QByteArray, QByteArray> _data =
1771 Memcached::mgetByKey(groupKey, keys, casValues, returnType);
1772 if (!_data.empty()) {
1773 auto i = _data.constBegin();
1774 while (i != _data.constEnd()) {
1775 T retVal;
1776 QDataStream in(i.value());
1777 in >> retVal;
1778 hash.insert(i.key(), retVal);
1779 ++i;
1780 }
1781 }
1782 return hash;
1783}
1784
1785inline bool Memcached::touch(QByteArrayView key,
1786 std::chrono::seconds expiration,
1787 MemcachedReturnType *returnType)
1788{
1789 return Memcached::touch(key, expiration.count(), returnType);
1790}
1791
1792inline bool Memcached::touchByKey(QByteArrayView groupKey,
1793 QByteArrayView key,
1794 std::chrono::seconds expiration,
1795 MemcachedReturnType *returnType)
1796{
1797 return Memcached::touchByKey(groupKey, key, expiration.count(), returnType);
1798}
1799
1800} // namespace Cutelyst
The Cutelyst Application.
Definition: application.h:43
The Cutelyst Context.
Definition: context.h:38
Cutelyst Memcached plugin.
Definition: memcached.h:158
static QByteArray getByKey(QByteArrayView groupKey, QByteArrayView key, uint64_t *cas=nullptr, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:573
static bool touchByKey(QByteArrayView groupKey, QByteArrayView key, time_t expiration, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:1321
static QHash< QByteArray, QByteArray > mgetByKey(QByteArrayView groupKey, const QByteArrayList &keys, QHash< QByteArray, uint64_t > *casValues=nullptr, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:1209
static const std::chrono::seconds expirationNotAddDuration
Definition: memcached.h:821
static bool cas(QByteArrayView key, const QByteArray &value, time_t expiration, uint64_t cas, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:1000
static bool flush(time_t expiration, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:1114
static bool set(QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:262
static bool incrementWithInitialByKey(QByteArrayView groupKey, QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:828
~Memcached() override
static bool add(QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:348
static const time_t expirationNotAdd
Definition: memcached.h:812
static QByteArray get(QByteArrayView key, uint64_t *cas=nullptr, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:519
static bool replace(QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:433
static bool casByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, uint64_t cas, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:1043
static bool decrementWithInitialByKey(QByteArrayView groupKey, QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:961
static bool decrementWithInitial(QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:930
static bool touch(QByteArrayView key, time_t expiration, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:1295
static bool incrementWithInitial(QByteArrayView key, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value=nullptr, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:797
static bool addByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:389
static bool setByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:303
static QHash< QByteArray, QByteArray > mget(const QByteArrayList &keys, QHash< QByteArray, uint64_t > *casValues=nullptr, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:1138
static bool replaceByKey(QByteArrayView groupKey, QByteArrayView key, const QByteArray &value, time_t expiration, MemcachedReturnType *returnType=nullptr)
Definition: memcached.cpp:474
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8