Skip to content

Commit

Permalink
Extract urls_expire_after as separate factory
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Mar 17, 2024
1 parent a4a4e38 commit d9e97f9
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions plextraktsync/util/Factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ def server_config(self):
return server_config.get_server(server_name)

@cached_property
def session(self):
from requests_cache import CachedSession

def urls_expire_after(self):
from plextraktsync.decorators.flatten import flatten_dict

if not self.run_config.cache:
from requests_cache import DO_NOT_CACHE

return {
"*": DO_NOT_CACHE,
}

@flatten_dict
def patch_plex_urls(patterns, base_urls, glob="*.plex.direct:*"):
"""
Expand All @@ -138,22 +143,19 @@ def patch_plex_urls(patterns, base_urls, glob="*.plex.direct:*"):
url = pattern.replace(glob, url)
yield url, expire

if self.run_config.cache:
urls_expire_after = patch_plex_urls(
self.config.http_cache.urls_expire_after,
self.server_config.base_urls,
)
else:
from requests_cache import DO_NOT_CACHE
return patch_plex_urls(
self.config.http_cache.urls_expire_after,
self.server_config.base_urls,
)

urls_expire_after = {
"*": DO_NOT_CACHE,
}
@cached_property
def session(self):
from requests_cache import CachedSession

return CachedSession(
cache_name=self.config.cache_path,
cache_control=True,
urls_expire_after=urls_expire_after,
urls_expire_after=self.urls_expire_after,
)

@cached_property
Expand Down

0 comments on commit d9e97f9

Please sign in to comment.