HandlerFeedGenerator: Add caching
This commit is contained in:
parent
f5eb36e7bb
commit
7bb7600d39
@ -43,8 +43,8 @@ std::vector<HandlerFeedGenerator::EntryRevisionPair> HandlerFeedGenerator::fetch
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Response HandlerFeedGenerator::generateAtom(const std::vector<HandlerFeedGenerator::EntryRevisionPair> &entries,
|
std::string HandlerFeedGenerator::generateAtom(const std::vector<HandlerFeedGenerator::EntryRevisionPair> &entries,
|
||||||
std::string filter)
|
std::string filter)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
@ -89,11 +89,7 @@ Response HandlerFeedGenerator::generateAtom(const std::vector<HandlerFeedGenerat
|
|||||||
atomheader.setVar("atomfeeduniqueid", utils::html_xss(this->urlProvider->atomFeed(filter)));
|
atomheader.setVar("atomfeeduniqueid", utils::html_xss(this->urlProvider->atomFeed(filter)));
|
||||||
atomheader.setVar("atomfeedupdate", utils::formatLocalDate(newestPublished, dateformat) + "Z");
|
atomheader.setVar("atomfeedupdate", utils::formatLocalDate(newestPublished, dateformat) + "Z");
|
||||||
|
|
||||||
Response result;
|
return atomheader.render() + stream.str();
|
||||||
result.setStatus(200);
|
|
||||||
result.setContentType("application/atom+xml");
|
|
||||||
result.setBody(atomheader.render() + stream.str());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Response HandlerFeedGenerator::handleRequest(const Request &r)
|
Response HandlerFeedGenerator::handleRequest(const Request &r)
|
||||||
@ -103,12 +99,26 @@ Response HandlerFeedGenerator::handleRequest(const Request &r)
|
|||||||
{
|
{
|
||||||
std::string type = r.get("type");
|
std::string type = r.get("type");
|
||||||
std::string categories = r.get("cats");
|
std::string categories = r.get("cats");
|
||||||
|
|
||||||
auto entries = fetchEntries(utils::split(categories, ','));
|
|
||||||
if(type == "atom")
|
if(type == "atom")
|
||||||
{
|
{
|
||||||
std::string filter = categories;
|
std::string filter = categories;
|
||||||
response = generateAtom(entries, filter);
|
Response result;
|
||||||
|
result.setStatus(200);
|
||||||
|
result.setContentType("application/atom+xml");
|
||||||
|
std::string cacheKey = "feed:atom:" + filter;
|
||||||
|
auto cached = this->cache->get(cacheKey);
|
||||||
|
if(cached)
|
||||||
|
{
|
||||||
|
result.setBody(cached.value());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto entries = fetchEntries(utils::split(categories, ','));
|
||||||
|
std::string feed = generateAtom(entries, filter);
|
||||||
|
result.setBody(feed);
|
||||||
|
this->cache->put(cacheKey, feed);
|
||||||
|
}
|
||||||
|
response = result;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,7 @@ class HandlerFeedGenerator : public Handler
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<EntryRevisionPair> fetchEntries(std::vector<std::string> categories);
|
std::vector<EntryRevisionPair> fetchEntries(std::vector<std::string> categories);
|
||||||
Response generateAtom(const std::vector<EntryRevisionPair> &entries, std::string atomtitle);
|
std::string generateAtom(const std::vector<EntryRevisionPair> &entries, std::string atomtitle);
|
||||||
Response generateRss(const std::vector<EntryRevisionPair> &entries);
|
Response generateRss(const std::vector<EntryRevisionPair> &entries);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -45,6 +45,7 @@ Response HandlerPageDelete::handleRequest(PageDao &pageDao, std::string pagename
|
|||||||
{
|
{
|
||||||
pageDao.deletePage(pagename);
|
pageDao.deletePage(pagename);
|
||||||
this->cache->removePrefix("page:"); // TODO: overkill?
|
this->cache->removePrefix("page:"); // TODO: overkill?
|
||||||
|
this->cache->removePrefix("feed:");
|
||||||
return Response::redirectTemporarily(this->urlProvider->index());
|
return Response::redirectTemporarily(this->urlProvider->index());
|
||||||
}
|
}
|
||||||
TemplatePage delPage = this->templ->getPage("page_deletion");
|
TemplatePage delPage = this->templ->getPage("page_deletion");
|
||||||
|
@ -101,6 +101,7 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename,
|
|||||||
pageDao.setCategories(pagename, cats);
|
pageDao.setCategories(pagename, cats);
|
||||||
this->database->commitTransaction();
|
this->database->commitTransaction();
|
||||||
this->cache->removePrefix("page:"); // TODO: overkill?
|
this->cache->removePrefix("page:"); // TODO: overkill?
|
||||||
|
this->cache->removePrefix("feed:");
|
||||||
}
|
}
|
||||||
catch(const DatabaseException &e)
|
catch(const DatabaseException &e)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user