HandlerFeedGenerator: Add caching
Esse commit está contido em:
pai
f5eb36e7bb
commit
7bb7600d39
@ -43,8 +43,8 @@ std::vector<HandlerFeedGenerator::EntryRevisionPair> HandlerFeedGenerator::fetch
|
||||
return result;
|
||||
}
|
||||
|
||||
Response HandlerFeedGenerator::generateAtom(const std::vector<HandlerFeedGenerator::EntryRevisionPair> &entries,
|
||||
std::string filter)
|
||||
std::string HandlerFeedGenerator::generateAtom(const std::vector<HandlerFeedGenerator::EntryRevisionPair> &entries,
|
||||
std::string filter)
|
||||
{
|
||||
|
||||
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("atomfeedupdate", utils::formatLocalDate(newestPublished, dateformat) + "Z");
|
||||
|
||||
Response result;
|
||||
result.setStatus(200);
|
||||
result.setContentType("application/atom+xml");
|
||||
result.setBody(atomheader.render() + stream.str());
|
||||
return result;
|
||||
return atomheader.render() + stream.str();
|
||||
}
|
||||
|
||||
Response HandlerFeedGenerator::handleRequest(const Request &r)
|
||||
@ -103,12 +99,26 @@ Response HandlerFeedGenerator::handleRequest(const Request &r)
|
||||
{
|
||||
std::string type = r.get("type");
|
||||
std::string categories = r.get("cats");
|
||||
|
||||
auto entries = fetchEntries(utils::split(categories, ','));
|
||||
if(type == "atom")
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ class HandlerFeedGenerator : public Handler
|
||||
|
||||
protected:
|
||||
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);
|
||||
|
||||
public:
|
||||
|
@ -45,6 +45,7 @@ Response HandlerPageDelete::handleRequest(PageDao &pageDao, std::string pagename
|
||||
{
|
||||
pageDao.deletePage(pagename);
|
||||
this->cache->removePrefix("page:"); // TODO: overkill?
|
||||
this->cache->removePrefix("feed:");
|
||||
return Response::redirectTemporarily(this->urlProvider->index());
|
||||
}
|
||||
TemplatePage delPage = this->templ->getPage("page_deletion");
|
||||
|
@ -101,6 +101,7 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename,
|
||||
pageDao.setCategories(pagename, cats);
|
||||
this->database->commitTransaction();
|
||||
this->cache->removePrefix("page:"); // TODO: overkill?
|
||||
this->cache->removePrefix("feed:");
|
||||
}
|
||||
catch(const DatabaseException &e)
|
||||
{
|
||||
|
Carregando…
Referência em uma nova issue
Block a user