Fetch data using the specified module :param bank: The name of the location inside the cache which will hold the key and its associated data. :param key: The name of the key (or file inside a directory) which will hold the da
(self, bank, key)
| 169 | return self.modules[fun](bank, key, data, **self.kwargs) |
| 170 | |
| 171 | def fetch(self, bank, key): |
| 172 | """ |
| 173 | Fetch data using the specified module |
| 174 | |
| 175 | :param bank: |
| 176 | The name of the location inside the cache which will hold the key |
| 177 | and its associated data. |
| 178 | |
| 179 | :param key: |
| 180 | The name of the key (or file inside a directory) which will hold |
| 181 | the data. File extensions should not be provided, as they will be |
| 182 | added by the driver itself. |
| 183 | |
| 184 | :return: |
| 185 | Return a python object fetched from the cache or an empty dict if |
| 186 | the given path or key not found. |
| 187 | |
| 188 | :raises SaltCacheError: |
| 189 | Raises an exception if cache driver detected an error accessing data |
| 190 | in the cache backend (auth, permissions, etc). |
| 191 | """ |
| 192 | fun = f"{self.driver}.fetch" |
| 193 | ret = self.modules[fun](bank, key, **self.kwargs) |
| 194 | |
| 195 | # handle fallback if necessary |
| 196 | if isinstance(ret, dict) and set(ret.keys()) == {"data", "_expires"}: |
| 197 | now = datetime.datetime.now().astimezone().timestamp() |
| 198 | if ret["_expires"] > now: |
| 199 | return ret["data"] |
| 200 | else: |
| 201 | return {} |
| 202 | else: |
| 203 | return ret |
| 204 | |
| 205 | def updated(self, bank, key): |
| 206 | """ |