[core] Use better types for modified / expires / etag

This commit is contained in:
John Firebaugh
2016-01-19 15:57:17 -08:00
parent c33ed50c98
commit 1c21d0fd4c
33 changed files with 231 additions and 169 deletions

View File

@@ -332,9 +332,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 = Seconds(getStmt->get<int64_t>(1));
response->etag = getStmt->get<std::string>(2);
response->expires = Seconds(getStmt->get<int64_t>(3));
response->modified = getStmt->get<optional<SystemTimePoint>>(1);
response->etag = getStmt->get<optional<std::string>>(2);
response->expires = getStmt->get<optional<SystemTimePoint>>(3);
response->data = std::make_shared<std::string>(getStmt->get<std::string>(4));
if (getStmt->get<int>(5)) { // == compressed
response->data = std::make_shared<std::string>(util::decompress(*response->data));
@@ -357,7 +357,7 @@ void SQLiteCache::Impl::get(const Resource &resource, Callback callback) {
accessedStmt->reset();
}
accessedStmt->bind(1, int64_t(toSeconds(SystemClock::now()).count()));
accessedStmt->bind(1, SystemClock::now());
accessedStmt->bind(2, canonicalURL.c_str());
accessedStmt->run();
}
@@ -419,10 +419,10 @@ void SQLiteCache::Impl::put(const Resource& resource, const Response& response)
putStmt->bind(2 /* status */, 1 /* success */);
}
putStmt->bind(3 /* kind */, int(resource.kind));
putStmt->bind(4 /* modified */, int64_t(response.modified.count()));
putStmt->bind(5 /* etag */, response.etag.c_str());
putStmt->bind(6 /* expires */, int64_t(response.expires.count()));
putStmt->bind(7 /* accessed */, int64_t(toSeconds(SystemClock::now()).count()));
putStmt->bind(4 /* modified */, response.modified);
putStmt->bind(5 /* etag */, response.etag);
putStmt->bind(6 /* expires */, response.expires);
putStmt->bind(7 /* accessed */, SystemClock::now());
std::string data;
if (resource.kind != Resource::SpriteImage && response.data) {
@@ -452,7 +452,7 @@ void SQLiteCache::Impl::put(const Resource& resource, const Response& response)
}
}
void SQLiteCache::Impl::refresh(const Resource& resource, Seconds expires) {
void SQLiteCache::Impl::refresh(const Resource& resource, optional<SystemTimePoint> expires) {
try {
initializeDatabase();
@@ -466,8 +466,8 @@ void SQLiteCache::Impl::refresh(const Resource& resource, Seconds expires) {
}
const auto canonicalURL = util::mapbox::canonicalURL(resource.url);
refreshStmt->bind(1, int64_t(toSeconds(SystemClock::now()).count()));
refreshStmt->bind(2, int64_t(expires.count()));
refreshStmt->bind(1, SystemClock::now());
refreshStmt->bind(2, expires);
refreshStmt->bind(3, canonicalURL.c_str());
refreshStmt->run();
} catch (mapbox::sqlite::Exception& ex) {