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