cutelyst  4.4.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/Plugins/memcached_export.h>
8 #include <Cutelyst/plugin.h>
9 #include <chrono>
10 
11 #include <QDataStream>
12 #include <QVersionNumber>
13 
14 namespace Cutelyst {
15 
16 class Context;
17 class MemcachedPrivate;
18 
166 class CUTELYST_PLUGIN_MEMCACHED_EXPORT Memcached // clazy:exclude=ctor-missing-parent-argument
167  : public Plugin
168 {
169  Q_OBJECT
170  Q_DECLARE_PRIVATE(Memcached) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
171  Q_DISABLE_COPY(Memcached)
172 public:
176  Memcached(Application *parent);
177 
186  Memcached(Application *parent, const QVariantMap &defaultConfig);
187 
191  ~Memcached() override;
192 
196  enum class ReturnType {
197  Success,
198  Failure,
199  HostLookupFailure,
200  ConnectionFailure,
202  WriteFailure,
203  ReadFailure,
204  UnknownReadFailure,
207  ProtocolError,
208  ClientError,
209  ServerError,
210  Error,
211  DataExists,
212  DataDoesNotExist,
213  NotStored,
214  Stored,
215  NotFound,
216  MemoryAllocationFailure,
217  PartialRead,
218  SomeErrors,
220  NoServers,
221  End,
222  Deleted,
223  Stat,
224  Errno,
225  NotSupported,
226  FetchNotFinished,
228  Timeout,
229  Buffered,
230  BadKeyProvided,
231  InvalidHostProtocol,
234  ServerMarkedDead,
235  UnknownStatKey,
237  E2Big,
238  InvalidArguments,
239  KeyTooBig,
240  AuthProblem,
241  AuthFailure,
242  AuthContinue,
243  ParseError,
245  ParseUserError,
246  Deprecated,
247  InProgress,
248  ServerTemporaryDisabled,
249  ServerMemoryAllocationFailure,
250  MaximumReturn,
251  PluginNotRegisterd
253  };
254  Q_ENUM(Memcached::ReturnType)
255 
256 
260  void setDefaultConfig(const QVariantMap &defaultConfig);
261 
274  static bool set(QByteArrayView key,
275  const QByteArray &value,
276  time_t expiration,
277  ReturnType *returnType = nullptr);
278 
283  inline static bool set(QByteArrayView key,
284  const QByteArray &value,
285  std::chrono::seconds expiration,
286  ReturnType *returnType = nullptr);
287 
302  template <typename T>
303  static bool set(QByteArrayView key,
304  const T &value,
305  time_t expiration,
306  ReturnType *returnType = nullptr);
307 
312  template <typename T>
313  static bool set(QByteArrayView key,
314  const T &value,
315  std::chrono::seconds expiration,
316  ReturnType *returnType = nullptr);
317 
334  static bool setByKey(QByteArrayView groupKey,
335  QByteArrayView key,
336  const QByteArray &value,
337  time_t expiration,
338  ReturnType *returnType = nullptr);
339 
344  inline static bool setByKey(QByteArrayView groupKey,
345  QByteArrayView key,
346  const QByteArray &value,
347  std::chrono::seconds expiration,
348  ReturnType *returnType = nullptr);
349 
367  template <typename T>
368  static bool setByKey(QByteArrayView groupKey,
369  QByteArrayView key,
370  const T &value,
371  time_t expiration,
372  ReturnType *returnType = nullptr);
373 
378  template <typename T>
379  static bool setByKey(QByteArrayView groupKey,
380  QByteArrayView key,
381  const T &value,
382  std::chrono::seconds expiration,
383  ReturnType *returnType = nullptr);
384 
400  static bool add(QByteArrayView key,
401  const QByteArray &value,
402  time_t expiration,
403  ReturnType *returnType = nullptr);
404 
409  inline static bool add(QByteArrayView key,
410  const QByteArray &value,
411  std::chrono::seconds expiration,
412  ReturnType *returnType = nullptr);
413 
432  template <typename T>
433  static bool add(QByteArrayView key,
434  const T &value,
435  time_t expiration,
436  ReturnType *returnType = nullptr);
437 
442  template <typename T>
443  static bool add(QByteArrayView key,
444  const T &value,
445  std::chrono::seconds expiration,
446  ReturnType *returnType = nullptr);
447 
467  static bool addByKey(QByteArrayView groupKey,
468  QByteArrayView key,
469  const QByteArray &value,
470  time_t expiration,
471  ReturnType *returnType = nullptr);
472 
477  inline static bool addByKey(QByteArrayView groupKey,
478  QByteArrayView key,
479  const QByteArray &value,
480  std::chrono::seconds expiration,
481  ReturnType *returnType = nullptr);
482 
504  template <typename T>
505  static bool addByKey(QByteArrayView groupKey,
506  QByteArrayView key,
507  const T &value,
508  time_t expiration,
509  ReturnType *returnType = nullptr);
510 
515  template <typename T>
516  static bool addByKey(QByteArrayView groupKey,
517  QByteArrayView key,
518  const T &value,
519  std::chrono::seconds expiration,
520  ReturnType *returnType = nullptr);
521 
537  static bool replace(QByteArrayView key,
538  const QByteArray &value,
539  time_t expiration,
540  ReturnType *returnType = nullptr);
541 
546  inline static bool replace(QByteArrayView key,
547  const QByteArray &value,
548  std::chrono::seconds expiration,
549  ReturnType *returnType = nullptr);
550 
568  template <typename T>
569  static bool replace(QByteArrayView key,
570  const T &value,
571  time_t expiration,
572  ReturnType *returnType = nullptr);
573 
578  template <typename T>
579  static bool replace(QByteArrayView key,
580  const T &value,
581  std::chrono::seconds expiration,
582  ReturnType *returnType = nullptr);
583 
603  static bool replaceByKey(QByteArrayView groupKey,
604  QByteArrayView key,
605  const QByteArray &value,
606  time_t expiration,
607  ReturnType *returnType = nullptr);
608 
613  inline static bool replaceByKey(QByteArrayView groupKey,
614  QByteArrayView key,
615  const QByteArray &value,
616  std::chrono::seconds expiration,
617  ReturnType *returnType = nullptr);
618 
640  template <typename T>
641  static bool replaceByKey(QByteArrayView groupKey,
642  QByteArrayView key,
643  const T &value,
644  time_t expiration,
645  ReturnType *returnType = nullptr);
646 
651  template <typename T>
652  static bool replaceByKey(QByteArrayView groupKey,
653  QByteArrayView key,
654  const T &value,
655  std::chrono::seconds expiration,
656  ReturnType *returnType = nullptr);
657 
675  static QByteArray
676  get(QByteArrayView key, uint64_t *cas = nullptr, ReturnType *returnType = nullptr);
677 
708  template <typename T>
709  static T get(QByteArrayView key, uint64_t *cas = nullptr, ReturnType *returnType = nullptr);
710 
731  static QByteArray getByKey(QByteArrayView groupKey,
732  QByteArrayView key,
733  uint64_t *cas = nullptr,
734  ReturnType *returnType = nullptr);
735 
771  template <typename T>
772  static T getByKey(QByteArrayView groupKey,
773  QByteArrayView key,
774  uint64_t *cas = nullptr,
775  ReturnType *returnType = nullptr);
776 
785  static bool remove(QByteArrayView key, ReturnType *returnType = nullptr);
786 
799  static bool
800  removeByKey(QByteArrayView groupKey, QByteArrayView key, ReturnType *returnType = nullptr);
801 
809  static bool exist(QByteArrayView key, ReturnType *returnType = nullptr);
810 
822  static bool
823  existByKey(QByteArrayView groupKey, QByteArrayView key, ReturnType *returnType = nullptr);
824 
830  static const time_t expirationNotAdd;
831 
839  static const std::chrono::seconds expirationNotAddDuration;
840 
856  static bool increment(QByteArrayView key,
857  uint32_t offset,
858  uint64_t *value = nullptr,
859  ReturnType *returnType = nullptr);
860 
879  static bool incrementByKey(QByteArrayView groupKey,
880  QByteArrayView key,
881  uint64_t offset,
882  uint64_t *value = nullptr,
883  ReturnType *returnType = nullptr);
884 
909  static bool incrementWithInitial(QByteArrayView key,
910  uint64_t offset,
911  uint64_t initial,
912  time_t expiration,
913  uint64_t *value = nullptr,
914  ReturnType *returnType = nullptr);
915 
920  inline static bool incrementWithInitial(QByteArrayView key,
921  uint64_t offset,
922  uint64_t initial,
923  std::chrono::seconds expiration,
924  uint64_t *value = nullptr,
925  ReturnType *returnType = nullptr);
926 
956  static bool incrementWithInitialByKey(QByteArrayView groupKey,
957  QByteArrayView key,
958  uint64_t offset,
959  uint64_t initial,
960  time_t expiration,
961  uint64_t *value = nullptr,
962  ReturnType *returnType = nullptr);
963 
968  inline static bool incrementWithInitialByKey(QByteArrayView groupKey,
969  QByteArrayView key,
970  uint64_t offset,
971  uint64_t initial,
972  std::chrono::seconds expiration,
973  uint64_t *value = nullptr,
974  ReturnType *returnType = nullptr);
975 
991  static bool decrement(QByteArrayView key,
992  uint32_t offset,
993  uint64_t *value = nullptr,
994  ReturnType *returnType = nullptr);
995 
1014  static bool decrementByKey(QByteArrayView groupKey,
1015  QByteArrayView key,
1016  uint64_t offset,
1017  uint64_t *value = nullptr,
1018  ReturnType *returnType = nullptr);
1019 
1044  static bool decrementWithInitial(QByteArrayView key,
1045  uint64_t offset,
1046  uint64_t initial,
1047  time_t expiration,
1048  uint64_t *value = nullptr,
1049  ReturnType *returnType = nullptr);
1050 
1055  inline static bool decrementWithInitial(QByteArrayView key,
1056  uint64_t offset,
1057  uint64_t initial,
1058  std::chrono::seconds expiration,
1059  uint64_t *value = nullptr,
1060  ReturnType *returnType = nullptr);
1061 
1091  static bool decrementWithInitialByKey(QByteArrayView groupKey,
1092  QByteArrayView key,
1093  uint64_t offset,
1094  uint64_t initial,
1095  time_t expiration,
1096  uint64_t *value = nullptr,
1097  ReturnType *returnType = nullptr);
1098 
1103  inline static bool decrementWithInitialByKey(QByteArrayView groupKey,
1104  QByteArrayView key,
1105  uint64_t offset,
1106  uint64_t initial,
1107  std::chrono::seconds expiration,
1108  uint64_t *value = nullptr,
1109  ReturnType *returnType = nullptr);
1110 
1123  static bool cas(QByteArrayView key,
1124  const QByteArray &value,
1125  time_t expiration,
1126  uint64_t cas,
1127  ReturnType *returnType = nullptr);
1128 
1133  inline static bool cas(QByteArrayView key,
1134  const QByteArray &value,
1135  std::chrono::seconds expiration,
1136  uint64_t cas,
1137  ReturnType *returnType = nullptr);
1138 
1153  template <typename T>
1154  static bool cas(QByteArrayView key,
1155  const T &value,
1156  time_t expiration,
1157  uint64_t cas,
1158  ReturnType *returnType = nullptr);
1159 
1164  template <typename T>
1165  static bool cas(QByteArrayView key,
1166  const T &value,
1167  std::chrono::seconds expiration,
1168  uint64_t cas,
1169  ReturnType *returnType = nullptr);
1170 
1189  static bool casByKey(QByteArrayView groupKey,
1190  QByteArrayView key,
1191  const QByteArray &value,
1192  time_t expiration,
1193  uint64_t cas,
1194  ReturnType *returnType = nullptr);
1195 
1200  inline static bool casByKey(QByteArrayView groupKey,
1201  QByteArrayView key,
1202  const QByteArray &value,
1203  std::chrono::seconds expiration,
1204  uint64_t cas,
1205  ReturnType *returnType = nullptr);
1206 
1227  template <typename T>
1228  static bool casByKey(QByteArrayView groupKey,
1229  QByteArrayView key,
1230  const T &value,
1231  time_t expiration,
1232  uint64_t cas,
1233  ReturnType *returnType = nullptr);
1234 
1239  template <typename T>
1240  static bool casByKey(QByteArrayView groupKey,
1241  QByteArrayView key,
1242  const T &value,
1243  std::chrono::seconds expiration,
1244  uint64_t cas,
1245  ReturnType *returnType = nullptr);
1246 
1255  static bool flushBuffers(ReturnType *returnType = nullptr);
1256 
1268  static bool flush(time_t expiration, ReturnType *returnType = nullptr);
1269 
1274  inline static bool flush(std::chrono::seconds expiration, ReturnType *returnType = nullptr);
1275 
1289  static QHash<QByteArray, QByteArray> mget(const QByteArrayList &keys,
1290  QHash<QByteArray, uint64_t> *casValues = nullptr,
1291  ReturnType *returnType = nullptr);
1292 
1308  template <typename T>
1309  static QHash<QByteArray, T> mget(const QByteArrayList &keys,
1310  QHash<QByteArray, uint64_t> *casValues = nullptr,
1311  ReturnType *returnType = nullptr);
1312 
1332  static QHash<QByteArray, QByteArray> mgetByKey(QByteArrayView groupKey,
1333  const QByteArrayList &keys,
1334  QHash<QByteArray, uint64_t> *casValues = nullptr,
1335  ReturnType *returnType = nullptr);
1336 
1358  template <typename T>
1359  static QHash<QByteArray, T> mgetByKey(QByteArrayView groupKey,
1360  const QByteArrayList &keys,
1361  QHash<QByteArray, uint64_t> *casValues = nullptr,
1362  ReturnType *returnType = nullptr);
1363 
1373  static bool touch(QByteArrayView key, time_t expiration, ReturnType *returnType = nullptr);
1374 
1379  inline static bool touch(QByteArrayView key,
1380  std::chrono::seconds expiration,
1381  ReturnType *returnType = nullptr);
1382 
1397  static bool touchByKey(QByteArrayView groupKey,
1398  QByteArrayView key,
1399  time_t expiration,
1400  ReturnType *returnType = nullptr);
1401 
1406  inline static bool touchByKey(QByteArrayView groupKey,
1407  QByteArrayView key,
1408  std::chrono::seconds expiration,
1409  ReturnType *returnType = nullptr);
1410 
1414  static QString errorString(Context *c, ReturnType rt);
1415 
1419  static QVersionNumber libMemcachedVersion();
1420 
1421 protected:
1425  bool setup(Application *app) override;
1426 
1427 private:
1428  const std::unique_ptr<MemcachedPrivate> d_ptr;
1429 };
1430 
1431 inline bool Memcached::set(QByteArrayView key,
1432  const QByteArray &value,
1433  std::chrono::seconds expiration,
1434  ReturnType *returnType)
1435 {
1436  return Memcached::set(key, value, expiration.count(), returnType);
1437 }
1438 
1439 template <typename T>
1440 bool Memcached::set(QByteArrayView key, const T &value, time_t expiration, ReturnType *returnType)
1441 {
1442  QByteArray data;
1444  out << value;
1445  return Memcached::set(key, data, expiration, returnType);
1446 }
1447 
1448 template <typename T>
1449 bool Memcached::set(QByteArrayView key,
1450  const T &value,
1451  std::chrono::seconds expiration,
1452  ReturnType *returnType)
1453 {
1454  return Memcached::set<T>(key, value, expiration.count(), returnType);
1455 }
1456 
1457 inline bool Memcached::setByKey(QByteArrayView groupKey,
1458  QByteArrayView key,
1459  const QByteArray &value,
1460  std::chrono::seconds expiration,
1461  ReturnType *returnType)
1462 {
1463  return Memcached::setByKey(groupKey, key, value, expiration.count(), returnType);
1464 }
1465 
1466 template <typename T>
1467 bool Memcached::setByKey(QByteArrayView groupKey,
1468  QByteArrayView key,
1469  const T &value,
1470  time_t expiration,
1471  ReturnType *returnType)
1472 {
1473  QByteArray data;
1475  out << value;
1476  return Memcached::setByKey(groupKey, key, data, expiration, returnType);
1477 }
1478 
1479 template <typename T>
1480 bool Memcached::setByKey(QByteArrayView groupKey,
1481  QByteArrayView key,
1482  const T &value,
1483  std::chrono::seconds expiration,
1484  ReturnType *returnType)
1485 {
1486  return Memcached::setByKey<T>(groupKey, key, value, expiration.count(), returnType);
1487 }
1488 
1489 inline bool Memcached::add(QByteArrayView key,
1490  const QByteArray &value,
1491  std::chrono::seconds expiration,
1492  ReturnType *returnType)
1493 {
1494  return Memcached::add(key, value, expiration.count(), returnType);
1495 }
1496 
1497 template <typename T>
1498 bool Memcached::add(QByteArrayView key, const T &value, time_t expiration, ReturnType *returnType)
1499 {
1500  QByteArray data;
1502  out << value;
1503  return Memcached::add(key, data, expiration, returnType);
1504 }
1505 
1506 template <typename T>
1507 bool Memcached::add(QByteArrayView key,
1508  const T &value,
1509  std::chrono::seconds expiration,
1510  ReturnType *returnType)
1511 {
1512  return Memcached::add<T>(key, value, expiration.count(), returnType);
1513 }
1514 
1515 inline bool Memcached::addByKey(QByteArrayView groupKey,
1516  QByteArrayView key,
1517  const QByteArray &value,
1518  std::chrono::seconds expiration,
1519  ReturnType *returnType)
1520 {
1521  return Memcached::addByKey(groupKey, key, value, expiration.count(), returnType);
1522 }
1523 
1524 template <typename T>
1525 bool Memcached::addByKey(QByteArrayView groupKey,
1526  QByteArrayView key,
1527  const T &value,
1528  time_t expiration,
1529  ReturnType *returnType)
1530 {
1531  QByteArray data;
1533  out << value;
1534  return Memcached::addByKey(groupKey, key, data, expiration, returnType);
1535 }
1536 
1537 template <typename T>
1538 bool Memcached::addByKey(QByteArrayView groupKey,
1539  QByteArrayView key,
1540  const T &value,
1541  std::chrono::seconds expiration,
1542  ReturnType *returnType)
1543 {
1544  return Memcached::addByKey<T>(groupKey, key, value, expiration.count(), returnType);
1545 }
1546 
1547 inline bool Memcached::replace(QByteArrayView key,
1548  const QByteArray &value,
1549  std::chrono::seconds expiration,
1550  ReturnType *returnType)
1551 {
1552  return Memcached::replace(key, value, expiration.count(), returnType);
1553 }
1554 
1555 template <typename T>
1556 bool Memcached::replace(QByteArrayView key,
1557  const T &value,
1558  time_t expiration,
1559  ReturnType *returnType)
1560 {
1561  QByteArray data;
1563  out << value;
1564  return Memcached::replace(key, data, expiration, returnType);
1565 }
1566 
1567 template <typename T>
1568 bool Memcached::replace(QByteArrayView key,
1569  const T &value,
1570  std::chrono::seconds expiration,
1571  ReturnType *returnType)
1572 {
1573  return Memcached::replace<T>(key, value, expiration.count(), returnType);
1574 }
1575 
1576 inline bool Memcached::replaceByKey(QByteArrayView groupKey,
1577  QByteArrayView key,
1578  const QByteArray &value,
1579  std::chrono::seconds expiration,
1580  ReturnType *returnType)
1581 {
1582  return Memcached::replaceByKey(groupKey, key, value, expiration.count(), returnType);
1583 }
1584 
1585 template <typename T>
1586 bool Memcached::replaceByKey(QByteArrayView groupKey,
1587  QByteArrayView key,
1588  const T &value,
1589  time_t expiration,
1590  ReturnType *returnType)
1591 {
1592  QByteArray data;
1594  out << value;
1595  return Memcached::replaceByKey(groupKey, key, data, expiration, returnType);
1596 }
1597 
1598 template <typename T>
1599 bool Memcached::replaceByKey(QByteArrayView groupKey,
1600  QByteArrayView key,
1601  const T &value,
1602  std::chrono::seconds expiration,
1603  ReturnType *returnType)
1604 {
1605  return Memcached::replaceByKey<T>(groupKey, key, value, expiration.count(), returnType);
1606 }
1607 
1608 inline bool Memcached::incrementWithInitial(QByteArrayView key,
1609  uint64_t offset,
1610  uint64_t initial,
1611  std::chrono::seconds expiration,
1612  uint64_t *value,
1613  ReturnType *returnType)
1614 {
1615  return Memcached::incrementWithInitial(
1616  key, offset, initial, expiration.count(), value, returnType);
1617 }
1618 
1619 inline bool Memcached::incrementWithInitialByKey(QByteArrayView groupKey,
1620  QByteArrayView key,
1621  uint64_t offset,
1622  uint64_t initial,
1623  std::chrono::seconds expiration,
1624  uint64_t *value,
1625  ReturnType *returnType)
1626 {
1627  return Memcached::incrementWithInitialByKey(
1628  groupKey, key, offset, initial, expiration.count(), value, returnType);
1629 }
1630 
1631 inline bool Memcached::decrementWithInitial(QByteArrayView key,
1632  uint64_t offset,
1633  uint64_t initial,
1634  std::chrono::seconds expiration,
1635  uint64_t *value,
1636  ReturnType *returnType)
1637 {
1638  return Memcached::decrementWithInitial(
1639  key, offset, initial, expiration.count(), value, returnType);
1640 }
1641 
1642 inline bool Memcached::decrementWithInitialByKey(QByteArrayView groupKey,
1643  QByteArrayView key,
1644  uint64_t offset,
1645  uint64_t initial,
1646  std::chrono::seconds expiration,
1647  uint64_t *value,
1648  ReturnType *returnType)
1649 {
1650  return Memcached::decrementWithInitialByKey(
1651  groupKey, key, offset, initial, expiration.count(), value, returnType);
1652 }
1653 
1654 template <typename T>
1655 T Memcached::get(QByteArrayView key, uint64_t *cas, ReturnType *returnType)
1656 {
1657  T retVal;
1658  QByteArray ba = Memcached::get(key, cas, returnType);
1659  if (!ba.isEmpty()) {
1661  in >> retVal;
1662  }
1663  return retVal;
1664 }
1665 
1666 template <typename T>
1667 T Memcached::getByKey(QByteArrayView groupKey,
1668  QByteArrayView key,
1669  uint64_t *cas,
1670  ReturnType *returnType)
1671 {
1672  T retVal;
1673  QByteArray ba = Memcached::getByKey(groupKey, key, cas, returnType);
1674  if (!ba.isEmpty()) {
1676  in >> retVal;
1677  }
1678  return retVal;
1679 }
1680 
1681 inline bool Memcached::cas(QByteArrayView key,
1682  const QByteArray &value,
1683  std::chrono::seconds expiration,
1684  uint64_t cas,
1685  ReturnType *returnType)
1686 {
1687  return Memcached::cas(key, value, expiration.count(), cas, returnType);
1688 }
1689 
1690 template <typename T>
1691 bool Memcached::cas(QByteArrayView key,
1692  const T &value,
1693  time_t expiration,
1694  uint64_t cas,
1695  ReturnType *returnType)
1696 {
1697  QByteArray data;
1699  out << value;
1700  return Memcached::cas(key, data, expiration, cas, returnType);
1701 }
1702 
1703 template <typename T>
1704 bool Memcached::cas(QByteArrayView key,
1705  const T &value,
1706  std::chrono::seconds expiration,
1707  uint64_t cas,
1708  ReturnType *returnType)
1709 {
1710  return Memcached::cas<T>(key, value, expiration.count(), cas, returnType);
1711 }
1712 
1713 inline bool Memcached::casByKey(QByteArrayView groupKey,
1714  QByteArrayView key,
1715  const QByteArray &value,
1716  std::chrono::seconds expiration,
1717  uint64_t cas,
1718  ReturnType *returnType)
1719 {
1720  return Memcached::casByKey(groupKey, key, value, expiration.count(), cas, returnType);
1721 }
1722 
1723 template <typename T>
1724 bool Memcached::casByKey(QByteArrayView groupKey,
1725  QByteArrayView key,
1726  const T &value,
1727  time_t expiration,
1728  uint64_t cas,
1729  ReturnType *returnType)
1730 {
1731  QByteArray data;
1733  out << value;
1734  return Memcached::casByKey(groupKey, key, data, expiration, cas, returnType);
1735 }
1736 
1737 template <typename T>
1738 bool Memcached::casByKey(QByteArrayView groupKey,
1739  QByteArrayView key,
1740  const T &value,
1741  std::chrono::seconds expiration,
1742  uint64_t cas,
1743  ReturnType *returnType)
1744 {
1745  return Memcached::casByKey<T>(groupKey, key, value, expiration.count(), cas, returnType);
1746 }
1747 
1748 inline bool Memcached::flush(std::chrono::seconds expiration, ReturnType *returnType)
1749 {
1750  return Memcached::flush(expiration.count(), returnType);
1751 }
1752 
1753 template <typename T>
1754 QHash<QByteArray, T> Memcached::mget(const QByteArrayList &keys,
1755  QHash<QByteArray, uint64_t> *casValues,
1756  ReturnType *returnType)
1757 {
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()) {
1763  T retVal;
1764  QDataStream in(i.value());
1765  in >> retVal;
1766  hash.insert(i.key(), retVal);
1767  ++i;
1768  }
1769  }
1770  return hash;
1771 }
1772 
1773 template <typename T>
1774 QHash<QByteArray, T> Memcached::mgetByKey(QByteArrayView groupKey,
1775  const QByteArrayList &keys,
1776  QHash<QByteArray, uint64_t> *casValues,
1777  ReturnType *returnType)
1778 {
1779  QHash<QByteArray, T> hash;
1781  Memcached::mgetByKey(groupKey, keys, casValues, returnType);
1782  if (!_data.empty()) {
1783  auto i = _data.constBegin();
1784  while (i != _data.constEnd()) {
1785  T retVal;
1786  QDataStream in(i.value());
1787  in >> retVal;
1788  hash.insert(i.key(), retVal);
1789  ++i;
1790  }
1791  }
1792  return hash;
1793 }
1794 
1795 inline bool
1796  Memcached::touch(QByteArrayView key, std::chrono::seconds expiration, ReturnType *returnType)
1797 {
1798  return Memcached::touch(key, expiration.count(), returnType);
1799 }
1800 
1801 inline bool Memcached::touchByKey(QByteArrayView groupKey,
1802  QByteArrayView key,
1803  std::chrono::seconds expiration,
1804  ReturnType *returnType)
1805 {
1806  return Memcached::touchByKey(groupKey, key, expiration.count(), returnType);
1807 }
1808 
1809 } // namespace Cutelyst
The Cutelyst application.
Definition: application.h:66
The Cutelyst Context.
Definition: context.h:42
Cutelyst Memcached plugin.
Definition: memcached.h:168
Base class for Cutelyst Plugins.
Definition: plugin.h:25
The Cutelyst namespace holds all public Cutelyst API.
bool isEmpty() const const
QHash::const_iterator constBegin() const const
QHash::const_iterator constEnd() const const
bool empty() const const
QHash::iterator insert(const Key &key, const T &value)