Save value for the given key. :param key: Must be a ``/`` separated value. Usually the first name is the name of your plugin or your application. :param value: Must be of any combination of basic python types, including nested types li
(self, key: str, value: object)
| 204 | return default |
| 205 | |
| 206 | def set(self, key: str, value: object) -> None: |
| 207 | """Save value for the given key. |
| 208 | |
| 209 | :param key: |
| 210 | Must be a ``/`` separated value. Usually the first |
| 211 | name is the name of your plugin or your application. |
| 212 | :param value: |
| 213 | Must be of any combination of basic python types, |
| 214 | including nested types like lists of dictionaries. |
| 215 | """ |
| 216 | path = self._getvaluepath(key) |
| 217 | try: |
| 218 | self._mkdir(path.parent) |
| 219 | except OSError as exc: |
| 220 | self.warn( |
| 221 | f"could not create cache path {path}: {exc}", |
| 222 | _ispytest=True, |
| 223 | ) |
| 224 | return |
| 225 | data = json.dumps(value, ensure_ascii=False, indent=2) |
| 226 | try: |
| 227 | f = path.open("w", encoding="UTF-8") |
| 228 | except OSError as exc: |
| 229 | self.warn( |
| 230 | f"cache could not write path {path}: {exc}", |
| 231 | _ispytest=True, |
| 232 | ) |
| 233 | else: |
| 234 | with f: |
| 235 | f.write(data) |
| 236 | |
| 237 | def _ensure_cache_dir_and_supporting_files(self) -> None: |
| 238 | """Create the cache dir and its supporting files.""" |