11 #include "string/format.h"
18 auto hanlder = [](CppCommon::FileCache &
cache,
const std::string& key,
const std::string& value,
const CppCommon::Timespan& timespan)
21 response.SetBegin(200);
22 response.SetContentType(CppCommon::Path(key).extension().
string());
23 response.SetHeader(
"Cache-Control", CppCommon::format(
"max-age={}", timespan.seconds()));
24 response.SetBody(value);
25 return cache.insert(key, response.cache(), timespan);
28 cache().insert_path(path, prefix, timeout, hanlder);
void AddStaticContent(const CppCommon::Path &path, const std::string &prefix="/", const CppCommon::Timespan &timeout=CppCommon::Timespan::hours(1))
Add static content cache.
CppCommon::FileCache & cache() noexcept
Get the static content cache.
C++ Server project definitions.