Loads a key, returning a `Future` for the value represented by that key.
(self, key=None)
| 72 | return self._loop |
| 73 | |
| 74 | def load(self, key=None): |
| 75 | """ |
| 76 | Loads a key, returning a `Future` for the value represented by that key. |
| 77 | """ |
| 78 | if key is None: |
| 79 | raise TypeError( # pragma: no cover |
| 80 | ( |
| 81 | "The loader.load() function must be called with a value, " |
| 82 | "but got: {}." |
| 83 | ).format(key) |
| 84 | ) |
| 85 | |
| 86 | cache_key = self.get_cache_key(key) |
| 87 | |
| 88 | # If caching and there is a cache-hit, return cached Future. |
| 89 | if self.cache: |
| 90 | cached_result = self._cache.get(cache_key) |
| 91 | if cached_result: |
| 92 | return cached_result |
| 93 | |
| 94 | # Otherwise, produce a new Future for this value. |
| 95 | future = self.loop.create_future() |
| 96 | # If caching, cache this Future. |
| 97 | if self.cache: |
| 98 | self._cache[cache_key] = future |
| 99 | |
| 100 | self.do_resolve_reject(key, future) |
| 101 | return future |
| 102 | |
| 103 | def do_resolve_reject(self, key, future): |
| 104 | # Enqueue this Future to be dispatched. |