| OLD | NEW |
| 1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 part of quiver.cache; | 15 part of quiver.cache; |
| 16 | 16 |
| 17 /** | 17 /// A function that produces a value for [key], for when a [Cache] needs to |
| 18 * A function that produces a value for [key], for when a [Cache] needs to | 18 /// populate an entry. |
| 19 * populate an entry. | 19 /// |
| 20 * | 20 /// The loader function should either return a value synchronously or a |
| 21 * The loader function should either return a value synchronously or a [Future] | 21 /// [Future] which completes with the value asynchronously. |
| 22 * which completes with the value asynchronously. | |
| 23 */ | |
| 24 typedef dynamic Loader<K>(K key); | 22 typedef dynamic Loader<K>(K key); |
| 25 | 23 |
| 26 /** | 24 /// A semi-persistent mapping of keys to values. |
| 27 * A semi-persistent mapping of keys to values. | 25 /// |
| 28 * | 26 /// All access to a Cache is asynchronous because many implementations will |
| 29 * All access to a Cache is asynchronous because many implementations will store | 27 /// store their entries in remote systems, isolates, or otherwise have to do |
| 30 * their entries in remote systems, isolates, or otherwise have to do async IO | 28 /// async IO to read and write. |
| 31 * to read and write. | |
| 32 */ | |
| 33 abstract class Cache<K, V> { | 29 abstract class Cache<K, V> { |
| 34 | 30 /// Returns the value associated with [key]. |
| 35 /** | |
| 36 * Returns the value associated with [key]. | |
| 37 */ | |
| 38 Future<V> get(K key, {Loader<K> ifAbsent}); | 31 Future<V> get(K key, {Loader<K> ifAbsent}); |
| 39 | 32 |
| 40 /** | 33 /// Sets the value associated with [key]. The Future completes with null when |
| 41 * Sets the value associated with [key]. The Future completes with null when | 34 /// the operation is complete. |
| 42 * the operation is complete. | |
| 43 */ | |
| 44 Future set(K key, V value); | 35 Future set(K key, V value); |
| 45 | 36 |
| 46 /** | 37 /// Removes the value associated with [key]. The Future completes with null |
| 47 * Removes the value associated with [key]. The Future completes with null | 38 /// when the operation is complete. |
| 48 * when the operation is complete. | |
| 49 */ | |
| 50 Future invalidate(K key); | 39 Future invalidate(K key); |
| 51 } | 40 } |
| OLD | NEW |