| 185 | return None |
| 186 | |
| 187 | def push(self, key: str, value: Union[str, dict]) -> None: |
| 188 | if isinstance(value, dict): |
| 189 | try: |
| 190 | value = py_json.dumps(value) |
| 191 | except TypeError as e: |
| 192 | raise ValueError(f"Unable to serialize value to JSON: {e}") |
| 193 | elif not isinstance(value, str): |
| 194 | raise ValueError( |
| 195 | f"value argument should be a string or dict, not {type(value).__name__}" |
| 196 | ) |
| 197 | |
| 198 | self.ensure_connection() |
| 199 | with self.lock: |
| 200 | with self.connection: |
| 201 | self.cursor.execute( |
| 202 | "INSERT OR REPLACE INTO cache VALUES (:0, :1)", |
| 203 | {"0": key, "1": value}, |
| 204 | ) |
| 205 | |
| 206 | def delete(self, key: str) -> None: |
| 207 | self.ensure_connection() |