Skip to content

Commit 6b59f7d

Browse files
bastimeyerback-to
authored andcommitted
utils: remove custom memoize decorator
1 parent d6f9001 commit 6b59f7d

File tree

4 files changed

+6
-17
lines changed

4 files changed

+6
-17
lines changed

src/streamlink/plugins/wwenetwork.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import json
22
import logging
33
import re
4+
from functools import lru_cache
45
from urllib.parse import parse_qsl, urlparse
56

67
from streamlink import PluginError
78
from streamlink.plugin import Plugin, PluginArgument, PluginArguments
89
from streamlink.plugin.api import useragents
910
from streamlink.stream import HLSStream
10-
from streamlink.utils import memoize
1111
from streamlink.utils.times import seconds_to_hhmmss
1212

1313
log = logging.getLogger(__name__)
@@ -91,7 +91,7 @@ def login(self, email, password):
9191
return self.auth_token
9292

9393
@property
94-
@memoize
94+
@lru_cache(maxsize=128)
9595
def item_config(self):
9696
log.debug("Loading page config")
9797
p = urlparse(self.url)

src/streamlink/session.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import pkgutil
33
from collections import OrderedDict
4+
from functools import lru_cache
45

56
import requests
67

@@ -10,7 +11,7 @@
1011
from streamlink.logger import StreamlinkLogger
1112
from streamlink.options import Options
1213
from streamlink.plugin import Plugin, api
13-
from streamlink.utils import load_module, memoize, update_scheme
14+
from streamlink.utils import load_module, update_scheme
1415
from streamlink.utils.l10n import Localization
1516

1617
# Ensure that the Logger class returned is Streamslink's for using the API (for backwards compatibility)
@@ -337,7 +338,7 @@ def get_plugin_option(self, plugin, key):
337338
plugin = self.plugins[plugin]
338339
return plugin.get_option(key)
339340

340-
@memoize
341+
@lru_cache(maxsize=128)
341342
def resolve_url(self, url, follow_redirect=True):
342343
"""Attempts to find a plugin that can use this URL.
343344

src/streamlink/utils/__init__.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import functools
21
import json
32
import re
43
import xml.etree.ElementTree as ET
@@ -151,18 +150,6 @@ def rtmpparse(url):
151150
return tcurl, playpath
152151

153152

154-
def memoize(obj):
155-
cache = obj.cache = {}
156-
157-
@functools.wraps(obj)
158-
def memoizer(*args, **kwargs):
159-
key = str(args) + str(kwargs)
160-
if key not in cache:
161-
cache[key] = obj(*args, **kwargs)
162-
return cache[key]
163-
return memoizer
164-
165-
166153
def search_dict(data, key):
167154
"""
168155
Search for a key in a nested dict, or list of nested dicts, and return the values.

tests/test_session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def test_resolve_url(self):
6868
plugin = session.resolve_url("http://test.se/channel")
6969
self.assertTrue(isinstance(plugin, Plugin))
7070
self.assertTrue(isinstance(plugin, plugins["testplugin"]))
71+
self.assertTrue(hasattr(session.resolve_url, "cache_info"), "resolve_url has a lookup cache")
7172

7273
def test_resolve_url_priority(self):
7374
from tests.plugin.testplugin import TestPlugin

0 commit comments

Comments
 (0)