| Index: blimp/common/blob_cache/in_memory_blob_cache.cc
|
| diff --git a/blimp/common/blob_cache/in_memory_blob_cache.cc b/blimp/common/blob_cache/in_memory_blob_cache.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5928faa4edefb9fb4a43217d9a8ddbb051f06241
|
| --- /dev/null
|
| +++ b/blimp/common/blob_cache/in_memory_blob_cache.cc
|
| @@ -0,0 +1,41 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "blimp/common/blob_cache/in_memory_blob_cache.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/sha1.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/string_util.h"
|
| +
|
| +namespace blimp {
|
| +
|
| +InMemoryBlobCache::InMemoryBlobCache() {}
|
| +
|
| +InMemoryBlobCache::~InMemoryBlobCache() {}
|
| +
|
| +void InMemoryBlobCache::Put(const BlobId& id, BlobData data) {
|
| + if (Contains(id)) {
|
| + // In cases where the engine has miscalculated what is already available
|
| + // on the client, Put() might be called unnecessarily, which should be
|
| + // ignored.
|
| + VLOG(2) << "Item with ID " << id << " already exists in cache.";
|
| + return;
|
| + }
|
| + cache_.insert(std::make_pair(id, std::move(data)));
|
| +}
|
| +
|
| +bool InMemoryBlobCache::Contains(const BlobId& id) const {
|
| + return cache_.find(id) != cache_.end();
|
| +}
|
| +
|
| +BlobData InMemoryBlobCache::Get(const BlobId& id) const {
|
| + if (!Contains(id)) {
|
| + return nullptr;
|
| + }
|
| +
|
| + return cache_.find(id)->second;
|
| +}
|
| +
|
| +} // namespace blimp
|
|
|