File cache example
#include <iostream>
int main(int argc, char** argv)
{
std::pair<bool, std::string_view> result;
result = cache.
find(
"123");
if (result.first)
std::cout << "Found: " << result.second << std::endl;
result = cache.
find(
"456");
if (result.first)
std::cout << "Found: " << result.second << std::endl;
result = cache.
find(
"123");
if (result.first)
std::cout << "Found: " << result.second << std::endl;
result = cache.
find(
"456");
if (result.first)
std::cout << "Found: " << result.second << std::endl;
return 0;
}
bool insert(const std::string &key, const std::string &value, const Timespan &timeout=Timespan(0))
Insert a new cache value with the given timeout into the file cache.
void watchdog(const UtcTimestamp &utc=UtcTimestamp())
Watchdog the file cache.
std::pair< bool, std::string_view > find(const std::string &key)
Try to find the cache value by the given key.
static void SleepFor(const Timespan ×pan) noexcept
Sleep the current thread for the given timespan.
int64_t milliseconds() const noexcept
Get total milliseconds of the current timespan.