Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HttpCache rules #1869

Merged
merged 3 commits into from
Mar 17, 2024
Merged

Update HttpCache rules #1869

merged 3 commits into from
Mar 17, 2024

Conversation

glensc
Copy link
Collaborator

@glensc glensc commented Mar 17, 2024

Walked all entries in my cache to see if some of them had missing match.

#!/usr/bin/env python
import fnmatch
from glob import glob

from requests_cache import CachedSession, DO_NOT_CACHE
from requests_cache.policy.expiration import _url_match

from plextraktsync.config.HttpCacheConfig import LONG_EXPIRY
from plextraktsync.factory import factory


def get_cache():
    session: CachedSession = factory.session

    return session.cache.responses


def match_policy(policy, url):
    for pattern, v in policy.items():
        matching = _url_match(url, pattern)
        if matching:
            # print(k, v)
            if v == LONG_EXPIRY:
                v = "LONG_EXPIRY"
            if v == DO_NOT_CACHE:
                v = "DO_NOT_CACHE"
            return (pattern, v)

    return None


def test():
    session: CachedSession = factory.session
    http_cache = factory.config.http_cache
    policy = http_cache.default_policy

    for r in get_cache().values():
        matching = match_policy(policy, r.url)
        if matching:
            # print(r.url, ": ", matching)
            continue
        print(r.url, ": NO MATCH")


if __name__ == "__main__":
    test()

@glensc glensc self-assigned this Mar 17, 2024
@glensc glensc merged commit 044ca3d into Taxel:main Mar 17, 2024
3 checks passed
@glensc glensc deleted the http-cache branch March 17, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant