(cls, *, url: str, cache_id=None, tags=None, session=None, throw_exc=True)
| 187 | |
| 188 | @classmethod |
| 189 | def proxy(cls, *, url: str, cache_id=None, tags=None, session=None, throw_exc=True) -> str: |
| 190 | if session is None: |
| 191 | session = requests |
| 192 | |
| 193 | if cls.get_location() is None: |
| 194 | resp = session.get(url) |
| 195 | if throw_exc: |
| 196 | resp.raise_for_status() |
| 197 | return resp.text |
| 198 | |
| 199 | cache_obj = cls(url=url, cache_id=cache_id, tags=tags) |
| 200 | |
| 201 | if cache_obj.is_valid: |
| 202 | logger.info(f"Loading {cache_obj.cid} from cache") |
| 203 | return cache_obj.fetch() |
| 204 | |
| 205 | try: |
| 206 | resp = session.get(url) |
| 207 | if throw_exc: |
| 208 | resp.raise_for_status() |
| 209 | cache_obj.cache_file_location.write_text(resp.text) |
| 210 | cache_obj.save_metadata() |
| 211 | return resp.text |
| 212 | except Exception: |
| 213 | cache_obj.delete() |
| 214 | raise |
| 215 | |
| 216 | @property |
| 217 | def metadata(self) -> dict: |
nothing calls this directly
no test coverage detected