OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:collection'; | 5 import 'dart:collection'; |
6 | 6 |
7 /** | 7 /** |
8 * Store of bytes associated with string keys. | 8 * Store of bytes associated with string keys. |
9 * | 9 * |
10 * Each key must be not longer than 100 characters and consist of only `[a-z]`, | 10 * Each key must be not longer than 100 characters and consist of only `[a-z]`, |
11 * `[0-9]`, `.` and `_` characters. It cannot have the sequence `..` in it. | 11 * `[0-9]`, `.` and `_` characters. The key cannot be an empty string, the |
| 12 * literal `.`, or contain the sequence `..`. |
12 * | 13 * |
13 * Note that associations are not guaranteed to be persistent. The value | 14 * Note that associations are not guaranteed to be persistent. The value |
14 * associated with a key can change or become `null` at any point in time. | 15 * associated with a key can change or become `null` at any point in time. |
| 16 * |
| 17 * TODO(scheglov) Research using asynchronous API. |
15 */ | 18 */ |
16 abstract class ByteStore { | 19 abstract class ByteStore { |
17 /** | 20 /** |
18 * Return the bytes associated with the given [key]. | 21 * Return the bytes associated with the given [key]. |
19 * Return `null` if the association does not exist. | 22 * Return `null` if the association does not exist. |
20 */ | 23 */ |
21 List<int> get(String key); | 24 List<int> get(String key); |
22 | 25 |
23 /** | 26 /** |
24 * Associate the given [bytes] with the [key]. | 27 * Associate the given [bytes] with the [key]. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 60 } |
58 | 61 |
59 void _evict() { | 62 void _evict() { |
60 if (_keys.length > maxEntries) { | 63 if (_keys.length > maxEntries) { |
61 String key = _keys.first; | 64 String key = _keys.first; |
62 _keys.remove(key); | 65 _keys.remove(key); |
63 _map.remove(key); | 66 _map.remove(key); |
64 } | 67 } |
65 } | 68 } |
66 } | 69 } |
OLD | NEW |