add cache for content type
This commit is contained in:
parent
69e9a75d15
commit
cd3bd950ae
@ -12,6 +12,7 @@ import tornado.routing
|
||||
import aiohttp
|
||||
import aiohttp_socks
|
||||
import stream_providers
|
||||
import expiringdict
|
||||
|
||||
logging.basicConfig(format='[%(filename)s:%(lineno)d] %(message)s', stream=sys.stdout, level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -31,6 +32,7 @@ icecast_server = os.environ.get("ICECAST_SERVER")
|
||||
stream_server = os.environ.get("STREAM_SERVER")
|
||||
proxy_server = os.environ.get("PROXY_SERVER")
|
||||
|
||||
ctype_cache = expiringdict.ExpiringDict(max_len=128, max_age_seconds=1800)
|
||||
class ProxyElem():
|
||||
def __init__(self, proxy):
|
||||
self.proxy = proxy
|
||||
@ -46,7 +48,9 @@ class ProxyElem():
|
||||
def __repr__(self):
|
||||
return str(self.proxy)
|
||||
async def content_type(self, url):
|
||||
ctype = None
|
||||
cached = ctype_cache.get(url)
|
||||
if isinstance(cached, str) and "binary" not in cached.lower():
|
||||
return cached
|
||||
async with self.session() as session:
|
||||
for i in range(5):
|
||||
try:
|
||||
@ -56,6 +60,7 @@ class ProxyElem():
|
||||
logger.info(e)
|
||||
else:
|
||||
if isinstance(ctype, str):
|
||||
ctype_cache[url] = ctype
|
||||
return ctype
|
||||
return "binary/octet-type"
|
||||
async def proxy_url(self, current, path):
|
||||
|
@ -167,7 +167,7 @@ class MetaRunner(StreamProvider):
|
||||
self.logger.info(e)
|
||||
return StreamData(None, data.get("og:image"), data.get("og:title"), data.get("og:description"), False)
|
||||
|
||||
upstream_cache = expiringdict.ExpiringDict(max_len=4096, max_age_seconds=1800)
|
||||
upstream_cache = expiringdict.ExpiringDict(max_len=512, max_age_seconds=1800)
|
||||
|
||||
async def get_from_runner(cache_key, runner, logger):
|
||||
result = None
|
||||
|
Loading…
Reference in New Issue
Block a user