mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Use the better cache in thexem
This commit is contained in:
parent
f110509ea0
commit
e034d51ae0
@ -1,29 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Dict, List, Literal
|
from typing import Dict, List, Literal
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta
|
||||||
from functools import wraps
|
|
||||||
|
|
||||||
from providers.utils import ProviderError
|
from providers.utils import ProviderError
|
||||||
|
from scanner.cache import cache
|
||||||
|
|
||||||
def cache(ttl: timedelta):
|
|
||||||
def wrap(func):
|
|
||||||
time, value = None, None
|
|
||||||
|
|
||||||
@wraps(func)
|
|
||||||
async def wrapped(*args, **kw):
|
|
||||||
nonlocal time
|
|
||||||
nonlocal value
|
|
||||||
now = datetime.now()
|
|
||||||
if not time or now - time > ttl:
|
|
||||||
value = await func(*args, **kw)
|
|
||||||
time = now
|
|
||||||
return value
|
|
||||||
|
|
||||||
return wrapped
|
|
||||||
|
|
||||||
return wrap
|
|
||||||
|
|
||||||
|
|
||||||
class TheXem:
|
class TheXem:
|
||||||
@ -31,7 +12,6 @@ class TheXem:
|
|||||||
self._client = client
|
self._client = client
|
||||||
self.base = "https://thexem.info"
|
self.base = "https://thexem.info"
|
||||||
|
|
||||||
# TODO: make the cache support different providers and handle concurrent calls to the function.
|
|
||||||
@cache(ttl=timedelta(days=1))
|
@cache(ttl=timedelta(days=1))
|
||||||
async def get_map(
|
async def get_map(
|
||||||
self, provider: Literal["tvdb"] | Literal["anidb"]
|
self, provider: Literal["tvdb"] | Literal["anidb"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user