@@ -57,6 +57,9 @@ class FileSystemRequestQueueClient(RequestQueueClient):
57
57
_STORAGE_SUBSUBDIR_DEFAULT = 'default'
58
58
"""The name of the subdirectory for the default request queue."""
59
59
60
+ _MAX_REQUESTS_IN_CACHE = 100_000
61
+ """Maximum number of requests to keep in cache for faster access."""
62
+
60
63
def __init__ (
61
64
self ,
62
65
* ,
@@ -112,9 +115,6 @@ def __init__(
112
115
self ._in_progress = set [str ]()
113
116
"""A set of request IDs that are currently being processed."""
114
117
115
- self ._cache_size = 50
116
- """Maximum number of requests to keep in cache."""
117
-
118
118
self ._request_cache = deque [Request ]()
119
119
"""Cache for requests: forefront requests at the beginning, regular requests at the end."""
120
120
@@ -463,10 +463,6 @@ async def fetch_next_request(self) -> Request | None:
463
463
if candidate .id not in self ._in_progress :
464
464
next_request = candidate
465
465
466
- # If cache is getting low, mark for refresh on next call.
467
- if len (self ._request_cache ) < self ._cache_size // 4 :
468
- self ._cache_needs_refresh = True
469
-
470
466
if next_request is not None :
471
467
self ._in_progress .add (next_request .id )
472
468
@@ -678,15 +674,15 @@ async def _update_metadata(
678
674
async def _refresh_cache (self ) -> None :
679
675
"""Refresh the request cache from filesystem.
680
676
681
- This method loads up to _cache_size requests from the filesystem,
677
+ This method loads up to _MAX_REQUESTS_IN_CACHE requests from the filesystem,
682
678
prioritizing forefront requests and maintaining proper ordering.
683
679
"""
684
680
self ._request_cache .clear ()
685
681
686
- request_files = await self ._get_request_files (self .path_to_rq )
682
+ forefront_requests = list [Request ]()
683
+ regular_requests = list [Request ]()
687
684
688
- forefront_requests = []
689
- regular_requests = []
685
+ request_files = await self ._get_request_files (self .path_to_rq )
690
686
691
687
for request_file in request_files :
692
688
request = await self ._parse_request_file (request_file )
@@ -726,13 +722,13 @@ async def _refresh_cache(self) -> None:
726
722
# Add forefront requests to the beginning of the cache (left side). Since forefront_requests are sorted
727
723
# by sequence (newest first), we need to add them in reverse order to maintain correct priority.
728
724
for request in reversed (forefront_requests ):
729
- if len (self ._request_cache ) >= self ._cache_size :
725
+ if len (self ._request_cache ) >= self ._MAX_REQUESTS_IN_CACHE :
730
726
break
731
727
self ._request_cache .appendleft (request )
732
728
733
729
# Add regular requests to the end of the cache (right side).
734
730
for request in regular_requests :
735
- if len (self ._request_cache ) >= self ._cache_size :
731
+ if len (self ._request_cache ) >= self ._MAX_REQUESTS_IN_CACHE :
736
732
break
737
733
self ._request_cache .append (request )
738
734
0 commit comments