diff options
| author | Jordan Cook <jordan.cook@pioneer.com> | 2021-08-10 12:40:32 -0500 |
|---|---|---|
| committer | Jordan Cook <jordan.cook@pioneer.com> | 2021-08-10 12:42:15 -0500 |
| commit | be8e9e9c8347b7707ecb16f7a6ff84f22070a4f6 (patch) | |
| tree | f50bb9b2876df20a3e5a576ea4a2dca93000984a /requests_cache/backends/sqlite.py | |
| parent | 6f21685411d6ba9c572b08cf9c3e1bd6a3dae1d6 (diff) | |
| download | requests-cache-be8e9e9c8347b7707ecb16f7a6ff84f22070a4f6.tar.gz | |
SQLite clear(): first attempt DROP TABLE, then delete and re-initialize the cache file if that fails
Diffstat (limited to 'requests_cache/backends/sqlite.py')
| -rw-r--r-- | requests_cache/backends/sqlite.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/requests_cache/backends/sqlite.py b/requests_cache/backends/sqlite.py index d6fef95..9fe59cb 100644 --- a/requests_cache/backends/sqlite.py +++ b/requests_cache/backends/sqlite.py @@ -49,13 +49,17 @@ class DbCache(BaseCache): self.redirects.vacuum() def clear(self): - """Clear the cache by deleting the cache file and re-initializing. This is done to allow - clear() to succeed even if the file is corrupted. + """Clear the cache. If this fails due to a corrupted cache or other I/O error, this will + attempt to delete the cache file and re-initialize. """ - if isfile(self.responses.db_path): - unlink(self.responses.db_path) - self.responses.init_db() - self.redirects.init_db() + try: + super().clear() + except Exception: + logger.exception('Failed to clear cache') + if isfile(self.responses.db_path): + unlink(self.responses.db_path) + self.responses.init_db() + self.redirects.init_db() class DbDict(BaseStorage): |
