Remove expired cache files
(self)
| 220 | ) |
| 221 | |
| 222 | async def _cleanup_expired_files(self): |
| 223 | """Remove expired cache files""" |
| 224 | try: |
| 225 | timeout = self.get_timeout() |
| 226 | if timeout <= 0: |
| 227 | return |
| 228 | current_time = time.time() |
| 229 | removed_count = 0 |
| 230 | |
| 231 | for file_path in self.cache_dir.iterdir(): |
| 232 | timeout = self.get_timeout() |
| 233 | if timeout <= 0: |
| 234 | debug_logger.log_info("Cache cleanup disabled during cleanup pass, stop deleting files") |
| 235 | break |
| 236 | if file_path.is_file(): |
| 237 | # Check file age |
| 238 | file_age = current_time - file_path.stat().st_mtime |
| 239 | if file_age > timeout: |
| 240 | try: |
| 241 | file_path.unlink() |
| 242 | removed_count += 1 |
| 243 | except Exception: |
| 244 | pass |
| 245 | |
| 246 | if removed_count > 0: |
| 247 | debug_logger.log_info(f"Cleanup: removed {removed_count} expired cache files") |
| 248 | |
| 249 | except Exception as e: |
| 250 | debug_logger.log_error( |
| 251 | error_message=f"Failed to cleanup expired files: {str(e)}", |
| 252 | status_code=0, |
| 253 | response_text="" |
| 254 | ) |
| 255 | |
| 256 | def _generate_cache_filename(self, url: str, media_type: str) -> str: |
| 257 | """Generate unique filename for cached file""" |
no test coverage detected