From 2a9bb4fa6121de62d9e6ba06d9a109ba6d57f14c Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Wed, 6 Jan 2021 19:37:26 +1100 Subject: cache code refactor --- src/protocols/abouthandler.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/protocols/abouthandler.cpp') 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 #include @@ -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())); -- cgit v1.2.3