OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #library('request_cache'); | 5 library request_cache; |
6 | 6 |
7 #import('dart:html'); | 7 import 'dart:html'; |
8 | 8 |
9 /** File system implementation using HTML5's Web Storage. */ | 9 /** File system implementation using HTML5's Web Storage. */ |
10 class HttpRequestCache { | 10 class HttpRequestCache { |
11 final Storage storage; | 11 final Storage storage; |
12 | 12 |
13 HttpRequestCache() : storage = window.sessionStorage; | 13 HttpRequestCache() : storage = window.sessionStorage; |
14 | 14 |
15 String readAll(String filename) { | 15 String readAll(String filename) { |
16 String response = storage[filename]; | 16 String response = storage[filename]; |
17 | 17 |
18 if (response == null) { | 18 if (response == null) { |
19 HttpRequest xr = new HttpRequest(); | 19 HttpRequest xr = new HttpRequest(); |
20 xr.open("GET", filename, false); | 20 xr.open("GET", filename, false); |
21 xr.send(); | 21 xr.send(); |
22 response = xr.responseText; | 22 response = xr.responseText; |
23 storage[filename] = response; | 23 storage[filename] = response; |
24 } | 24 } |
25 return response; | 25 return response; |
26 } | 26 } |
27 } | 27 } |
OLD | NEW |