diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-01-06 19:37:26 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-01-06 10:51:18 +0100 |
| commit | 2a9bb4fa6121de62d9e6ba06d9a109ba6d57f14c (patch) | |
| tree | 7f2b49ca97071b003697ffeaaa904ce1dfe166d6 /src/protocols | |
| parent | 24086fdfe92814c38da6d219916ee9d45d8ba581 (diff) | |
cache code refactor
Diffstat (limited to 'src/protocols')
| -rw-r--r-- | src/protocols/abouthandler.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/protocols/abouthandler.cpp b/src/protocols/abouthandler.cpp index 4ab789b..784e1bb 100644 --- a/src/protocols/abouthandler.cpp +++ b/src/protocols/abouthandler.cpp @@ -1,5 +1,6 @@ #include "abouthandler.hpp" #include "kristall.hpp" +#include "ioutil.hpp" #include <QUrl> #include <QFile> @@ -48,6 +49,27 @@ bool AboutHandler::startRequest(const QUrl &url, ProtocolHandler::RequestOptions emit this->requestComplete(document, "text/gemini"); } + else if (url.path() == "cache") + { + QByteArray document; + document.append("# Cache information\n"); + + auto& cache = kristall::cache.getPages(); + long unsigned cache_usage = 0; + int cached_count = 0; + for (auto it = cache.begin(); it != cache.end(); ++it, ++cached_count) + { + cache_usage += (long unsigned)it->second->body.size(); + } + + document.append(QString( + "In-memory cache usage:\n" + "* %1 used\n" + "* %2 pages in cache\n") + .arg(IoUtil::size_human(cache_usage), QString::number(cached_count))); + + emit this->requestComplete(document, "text/gemini"); + } else { QFile file(QString(":/about/%1.gemini").arg(url.path())); |
