[core] Replace time_t with std::chrono::seconds
Added aliases for std::chrono typedefs (eg. 'Seconds' for std::chrono::seconds). These aliases are used together with templated helper functions to replace time_t with std::chrono::seconds for most cases, in particular for 'modified' and 'expires' values in Response.
This commit is contained in:
@@ -118,9 +118,9 @@ void SQLiteCache::Impl::get(const Resource &resource, Callback callback) {
|
||||
// Status codes > 1 indicate an error
|
||||
response->error = std::make_unique<Response::Error>(Response::Error::Reason(status));
|
||||
}
|
||||
response->modified = getStmt->get<int64_t>(1);
|
||||
response->modified = Seconds(getStmt->get<Seconds::rep>(1));
|
||||
response->etag = getStmt->get<std::string>(2);
|
||||
response->expires = getStmt->get<int64_t>(3);
|
||||
response->expires = Seconds(getStmt->get<Seconds::rep>(3));
|
||||
response->data = std::make_shared<std::string>(std::move(getStmt->get<std::string>(4)));
|
||||
if (getStmt->get<int>(5)) { // == compressed
|
||||
response->data = std::make_shared<std::string>(std::move(util::decompress(*response->data)));
|
||||
@@ -177,9 +177,9 @@ void SQLiteCache::Impl::put(const Resource& resource, std::shared_ptr<const Resp
|
||||
putStmt->bind(2 /* status */, 1 /* success */);
|
||||
}
|
||||
putStmt->bind(3 /* kind */, int(resource.kind));
|
||||
putStmt->bind(4 /* modified */, response->modified);
|
||||
putStmt->bind(4 /* modified */, response->modified.count());
|
||||
putStmt->bind(5 /* etag */, response->etag.c_str());
|
||||
putStmt->bind(6 /* expires */, response->expires);
|
||||
putStmt->bind(6 /* expires */, response->expires.count());
|
||||
|
||||
std::string data;
|
||||
if (resource.kind != Resource::SpriteImage && response->data) {
|
||||
@@ -208,7 +208,7 @@ void SQLiteCache::Impl::put(const Resource& resource, std::shared_ptr<const Resp
|
||||
}
|
||||
}
|
||||
|
||||
void SQLiteCache::Impl::refresh(const Resource& resource, int64_t expires) {
|
||||
void SQLiteCache::Impl::refresh(const Resource& resource, Seconds expires) {
|
||||
try {
|
||||
if (!db) {
|
||||
createDatabase();
|
||||
@@ -226,7 +226,7 @@ void SQLiteCache::Impl::refresh(const Resource& resource, int64_t expires) {
|
||||
}
|
||||
|
||||
const auto canonicalURL = util::mapbox::canonicalURL(resource.url);
|
||||
refreshStmt->bind(1, int64_t(expires));
|
||||
refreshStmt->bind(1, expires.count());
|
||||
refreshStmt->bind(2, canonicalURL.c_str());
|
||||
refreshStmt->run();
|
||||
} catch (mapbox::sqlite::Exception& ex) {
|
||||
|
||||
Reference in New Issue
Block a user