Print cache sorted by size
+from functools import partial
+
import click
from requests_cache import CachedSession
from plex_trakt_sync.path import trakt_cache
+def get_sorted_cache(session: CachedSession):
+ sorter = partial(sorted, reverse=True, key=lambda x: len(x[1].content))
+ yield from sorter(session.cache._get_valid_responses())
+
+
@click.command()
def cache():
"""
@@ -13,5 +20,5 @@ def cache():
click.echo(f"Cache status:\n{session.cache}\n")
click.echo(f"URLs:")
- for url in session.cache.urls:
- click.echo(f"- {url}")
+ for k, r in get_sorted_cache(session):
+ click.echo(f"- {r.created_at}: {r.url}: {len(r.content)} bytes")
