Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: services/url_response_disk_cache/url_response_disk_cache_db.cc

Issue 1351693007: Add invalidation to url_response_disk_cache. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: services/url_response_disk_cache/url_response_disk_cache_db.cc
diff --git a/services/url_response_disk_cache/url_response_disk_cache_db.cc b/services/url_response_disk_cache/url_response_disk_cache_db.cc
index 4e65c01804b896ce0b8b44967c57a5fe3fbeb689..1991b623e38995aaeb9e1d1599d895932353461c 100644
--- a/services/url_response_disk_cache/url_response_disk_cache_db.cc
+++ b/services/url_response_disk_cache/url_response_disk_cache_db.cc
@@ -168,13 +168,7 @@ void URLResponseDiskCacheDB::SetVersion(uint64_t version) {
DCHECK(status.ok());
}
-void URLResponseDiskCacheDB::PutNew(const std::string& request_origin,
- const std::string& url,
- CacheEntryPtr entry) {
- CacheKeyPtr key = CacheKey::New();
- key->request_origin = request_origin;
- key->url = url;
- key->timestamp = base::Time::Now().ToInternalValue();
+void URLResponseDiskCacheDB::Put(CacheKeyPtr key, CacheEntryPtr entry) {
std::string key_string;
Serialize(key.Pass(), &key_string);
std::string entry_string;
@@ -184,9 +178,34 @@ void URLResponseDiskCacheDB::PutNew(const std::string& request_origin,
DCHECK(s.ok());
}
+CacheEntryPtr URLResponseDiskCacheDB::Get(CacheKeyPtr key) {
+ std::string key_string;
+ std::string entry_string;
+ Serialize(key.Pass(), &key_string);
+ leveldb::Status status =
+ db_->Get(leveldb::ReadOptions(), key_string, &entry_string);
+ if (status.IsNotFound())
+ return CacheEntryPtr();
+ DCHECK(status.ok());
+ CacheEntryPtr result;
+ Deserialize(entry_string, &result);
+ return result.Pass();
+}
+
+void URLResponseDiskCacheDB::PutNew(const std::string& request_origin,
+ const std::string& url,
+ CacheEntryPtr entry) {
+ CacheKeyPtr key = CacheKey::New();
+ key->request_origin = request_origin;
+ key->url = url;
+ key->timestamp = base::Time::Now().ToInternalValue();
+ Put(key.Pass(), entry.Pass());
+}
+
CacheEntryPtr URLResponseDiskCacheDB::GetNewest(
const std::string& request_origin,
- const std::string& url) {
+ const std::string& url,
+ CacheKeyPtr* output_key) {
CacheKeyPtr key = CacheKey::New();
key->request_origin = request_origin;
key->url = url;
@@ -200,6 +219,9 @@ CacheEntryPtr URLResponseDiskCacheDB::GetNewest(
Deserialize(it->key(), &key);
if (key->request_origin == request_origin && key->url == url) {
Deserialize(it->value(), &result);
+ if (output_key) {
+ *output_key = key.Pass();
+ }
}
}
return result.Pass();

Powered by Google App Engine
This is Rietveld 408576698