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

Unified Diff: sky/sdk/lib/framework/net/image_cache.dart

Issue 1165753004: Implement a simple image cache for Sky in Dart (no eviction) (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/framework/net/image_cache.dart
diff --git a/sky/sdk/lib/framework/net/image_cache.dart b/sky/sdk/lib/framework/net/image_cache.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f03b7a0a4885d1e81f400ddebd16b35854e50aa8
--- /dev/null
+++ b/sky/sdk/lib/framework/net/image_cache.dart
@@ -0,0 +1,30 @@
+// Copyright 2015 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.
+
+import 'dart:sky' as sky;
+import 'dart:collection';
+
+class ImageCache {
abarth-chromium 2015/06/02 00:52:47 There's no need for this class. You can just put
jackson 2015/06/02 01:18:25 Acknowledged.
+ static final ImageCache _sharedCache = new ImageCache();
+ static ImageCache shared() { return _sharedCache; }
+
+ final HashMap pendingRequests = new HashMap<String, List<sky.ImageLoaderCallback>>();
+ final HashMap completedRequests = new HashMap<String, sky.Image>();
abarth-chromium 2015/06/02 00:52:47 It's more important to put the types on the declar
jackson 2015/06/02 01:18:25 Acknowledged.
+
+ void load(String url, sky.ImageLoaderCallback callback) {
+ if (completedRequests.containsKey(url)) {
+ callback(completedRequests[url]);
+ } else if (pendingRequests.containsKey(url)) {
abarth-chromium 2015/06/02 00:52:47 Using putIfAbsent [1] is the idiomatic (and faster
jackson 2015/06/02 01:18:25 Acknowledged.
+ pendingRequests[url].add(callback);
+ } else {
+ pendingRequests[url] = new List();
+ pendingRequests[url].add(callback);
+ new sky.ImageLoader(url, (image) {
+ completedRequests[url] = image;
+ pendingRequests[url].forEach((c) => c(image));
+ pendingRequests[url].remove(url);
+ }).load();
+ }
+ }
+}
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698