[ie/youtube] Remove max_size memory cache option

This commit is contained in:
coletdjnz 2025-04-12 08:46:23 +12:00
parent 038699cae6
commit 18f89ca016
No known key found for this signature in database
GPG Key ID: 91984263BB39894A
3 changed files with 3 additions and 22 deletions

View File

@ -1789,9 +1789,6 @@ The following extractors use this feature:
* `pot_debug`: Enable debug logging for PO Token fetching. Either `true` or `false` (default `false`)
* `fetch_pot`: Policy to use for fetching a PO Token from providers. `always` to always try fetch a PO Token regardless if the client requires one for the given context. `when_required` to only fetch a PO Token if the client requires one for the given context (default)
###### youtubepot-memory
* `max_size`: Max size of the PO Token LRU memory cache (default 25)
###### youtubepot-webpo
* `bind_to_visitor_id`: Whether to use the Visitor ID instead of Visitor Data for caching WebPO tokens. Either `true` or `false` (default `true`)

View File

@ -4,7 +4,7 @@ from collections import OrderedDict
import pytest
from yt_dlp.extractor.youtube.pot._provider import IEContentProvider, BuiltInIEContentProvider
from yt_dlp.utils import bug_reports_message
from yt_dlp.extractor.youtube.pot.builtin.cache.memory import MemoryLRUPCP, memorylru_preference
from yt_dlp.extractor.youtube.pot.builtin.cache.memory import MemoryLRUPCP, memorylru_preference, initialize_global_cache
from yt_dlp.version import __version__
from yt_dlp.globals import _pot_memory_cache, _pot_cache_providers
@ -94,20 +94,6 @@ class TestMemoryLRUPCS:
assert len(pcp.cache) == 0
assert pcp.get('key1') is None
def test_max_size_setting(self, ie, logger):
MAX_SIZE = 5
called_max_size = 0
def initialize_cache(max_size):
nonlocal called_max_size
called_max_size = max_size
return OrderedDict(), threading.Lock(), max_size
pcp = MemoryLRUPCP(ie, logger, {'max_size': [str(MAX_SIZE)]}, initialize_cache=initialize_cache)
assert called_max_size == MAX_SIZE
assert pcp.max_size == MAX_SIZE
def test_use_global_cache_default(self, ie, logger):
pcp = MemoryLRUPCP(ie, logger, {})
assert pcp.max_size == _pot_memory_cache.value['max_size'] == 25
@ -123,7 +109,7 @@ class TestMemoryLRUPCS:
pcp = MemoryLRUPCP(ie, logger, {})
assert pcp.max_size == _pot_memory_cache.value['max_size'] == 25
with pytest.raises(ValueError, match='Cannot change max_size of initialized global memory cache'):
MemoryLRUPCP(ie, logger, {'max_size': ['50']})
initialize_global_cache(50)
assert pcp.max_size == _pot_memory_cache.value['max_size'] == 25

View File

@ -12,7 +12,6 @@ from yt_dlp.extractor.youtube.pot.cache import (
register_pcp_preference,
)
from yt_dlp.globals import _pot_memory_cache
from yt_dlp.utils import int_or_none
def initialize_global_cache(max_size: int):
@ -39,8 +38,7 @@ class MemoryLRUPCP(PoTokenCacheProvider, BuiltInIEContentProvider):
**kwargs,
):
super().__init__(*args, **kwargs)
self.cache, self.lock, self.max_size = initialize_cache(
int_or_none(self.settings.get('max_size', [''])[0]) or self.DEFAULT_CACHE_SIZE)
self.cache, self.lock, self.max_size = initialize_cache(self.DEFAULT_CACHE_SIZE)
def is_available(self) -> bool:
return True