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

Side by Side Diff: tools/gardening/lib/src/cache.dart

Issue 2797253006: Add find_timeouts and caching to tools/gardening (Closed)
Patch Set: Updated cf. comments Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « tools/gardening/lib/src/buildbot_structures.dart ('k') | tools/gardening/lib/src/logdog.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:io';
7
8 import 'util.dart';
9
10 final Cache cache = new Cache(Uri.base.resolve('temp/gardening-cache/'));
11
12 /// Simple cache for test step output.
13 class Cache {
14 Uri base;
15
16 Cache(this.base);
17
18 Map<String, String> memoryCache = <String, String>{};
19
20 /// Load the cache text for [path] or call [ifAbsent] to fetch the data.
21 Future<String> read(String path, Future<String> ifAbsent()) async {
22 if (memoryCache.containsKey(path)) {
23 log('Found $path in memory cache');
24 return memoryCache[path];
25 }
26 File file = new File.fromUri(base.resolve(path));
27 String text;
28 if (file.existsSync()) {
29 log('Found $path in file cache');
30 text = file.readAsStringSync();
31 memoryCache[path] = text;
32 } else {
33 log('Loading $path');
34 text = await ifAbsent();
35 write(path, text);
36 }
37 return text;
38 }
39
40 /// Store [text] as the cache data for [path].
41 void write(String path, String text) {
42 log('Creating $path in file cache');
43 File file = new File.fromUri(base.resolve(path));
44 file.createSync(recursive: true);
45 file.writeAsStringSync(text);
46 memoryCache[path] = text;
47 }
48 }
OLDNEW
« no previous file with comments | « tools/gardening/lib/src/buildbot_structures.dart ('k') | tools/gardening/lib/src/logdog.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698