@@ -29,6 +29,8 @@ class CleanerKwargs(TypedDict):
29
29
lock_validity_period : float
30
30
use_database : bool
31
31
depth : int
32
+ batch_size : int | None
33
+ batch_delay : float
32
34
33
35
34
36
def _cache_cleaner () -> None :
@@ -40,6 +42,8 @@ def _cache_cleaner() -> None:
40
42
lock_validity_period = float (os .environ .get ("LOCK_VALIDITY_PERIOD" , 86400 )),
41
43
use_database = use_database ,
42
44
depth = int (os .getenv ("CACHE_DEPTH" , 2 )),
45
+ batch_size = int (os .getenv ("BATCH_SIZE" , 0 )) or None ,
46
+ batch_delay = float (os .getenv ("BATCH_DELAY" , 0 )),
43
47
)
44
48
for cache_files_urlpath in utils .parse_data_volumes_config ():
45
49
cacholote .config .set (cache_files_urlpath = cache_files_urlpath )
@@ -77,6 +81,20 @@ def _expire_cache_entries(
77
81
delete : Annotated [
78
82
bool , Option ("--delete" , help = "Delete entries to expire" )
79
83
] = False ,
84
+ batch_size : Annotated [
85
+ int | None ,
86
+ Option (help = "Number of entries to process in each batch" ),
87
+ ] = None ,
88
+ batch_delay : Annotated [
89
+ float ,
90
+ Option (
91
+ help = "Delay in seconds between processing batches" ,
92
+ ),
93
+ ] = 0 ,
94
+ dry_run : Annotated [
95
+ bool ,
96
+ Option ("--dry-run" , help = "Perform a trial run that doesn't make any changes" ),
97
+ ] = False ,
80
98
) -> int :
81
99
"""Expire cache entries."""
82
100
if (all_collections and collection_id ) or not (all_collections or collection_id ):
@@ -89,8 +107,11 @@ def _expire_cache_entries(
89
107
before = _add_tzinfo (before ),
90
108
after = _add_tzinfo (after ),
91
109
delete = delete ,
110
+ batch_size = batch_size ,
111
+ batch_delay = batch_delay ,
112
+ dry_run = dry_run ,
92
113
)
93
- typer .echo (f"Number of entries expired: { count } " )
114
+ typer .echo (f"Number of entries { 'to expire' if dry_run else ' expired' } : { count } " )
94
115
return count
95
116
96
117
0 commit comments