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

Unified Diff: ui/file_manager/file_manager/background/js/metadata_proxy.js

Issue 2856533003: Add background-wide file metadata cache. (Closed)
Patch Set: Rename global_metadata_cache to metadata_proxy. Created 3 years, 7 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: ui/file_manager/file_manager/background/js/metadata_proxy.js
diff --git a/ui/file_manager/file_manager/background/js/metadata_proxy.js b/ui/file_manager/file_manager/background/js/metadata_proxy.js
new file mode 100644
index 0000000000000000000000000000000000000000..b664fd2f13e35c591b350be8e9b678fd5b667d8a
--- /dev/null
+++ b/ui/file_manager/file_manager/background/js/metadata_proxy.js
@@ -0,0 +1,38 @@
+// Copyright 2017 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.
+
+// Namespace
+var metadataProxy = {};
+
+/**
+ * Maximum number of entries whose metadata can be cached.
+ * @const {number}
+ * @private
+ */
+metadataProxy.MAX_CACHED_METADATA_ = 10000;
+
+/**
+ * @private {!LRUCache<!Metadata>}
+ */
+metadataProxy.cache_ = new LRUCache(metadataProxy.MAX_CACHED_METADATA_);
+
+/**
+ * Returns metadata for the given FileEntry. Uses cached metadata if possible.
+ *
+ * @param {!FileEntry} entry
+ * @return {!Promise.<!Metadata>}
+ */
+metadataProxy.getEntryMetadata = function(entry) {
+ var entryURL = entry.toURL();
+ if (metadataProxy.cache_.hasKey(entryURL)) {
+ return Promise.resolve(metadataProxy.cache_.get(entryURL));
+ } else {
+ return new Promise(function(resolve, reject) {
+ entry.getMetadata(function(metadata) {
+ metadataProxy.cache_.put(entryURL, metadata);
+ resolve(metadata);
+ }, reject);
+ });
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698