@@ -455,6 +455,51 @@ def __ager(cache_fn, fn, del_fn=False):
455455 fs .clear_expired_cache ()
456456
457457
458+ def test_simplecache_clear_expired_uses_file_times (tmp_path ):
459+ source = tmp_path / "source"
460+ source .mkdir ()
461+ old_source = source / "old"
462+ recent_source = source / "recent"
463+ cache = tmp_path / "cache"
464+ fs = fsspec .filesystem (
465+ "simplecache" ,
466+ target_protocol = "file" ,
467+ cache_storage = str (cache ),
468+ skip_instance_cache = True ,
469+ )
470+
471+ with fs .open (str (old_source ), "wb" ) as f :
472+ f .write (b"old" )
473+ with fs .open (str (recent_source ), "wb" ) as f :
474+ f .write (b"recent" )
475+ old_cached = fs ._check_file (fs ._strip_protocol (str (old_source )))
476+ recent_cached = fs ._check_file (fs ._strip_protocol (str (recent_source )))
477+ assert old_cached is not None
478+ assert recent_cached is not None
479+ os .utime (old_cached , (1 , 1 ))
480+
481+ fs .clear_expired_cache (expiry_time = 60 )
482+
483+ assert not os .path .exists (old_cached )
484+ assert os .path .exists (recent_cached )
485+ assert cache .is_dir ()
486+
487+
488+ def test_simplecache_clear_expired_requires_age (tmp_path ):
489+ fs = fsspec .filesystem (
490+ "simplecache" ,
491+ target_protocol = "file" ,
492+ cache_storage = str (tmp_path / "cache" ),
493+ skip_instance_cache = True ,
494+ )
495+
496+ with pytest .raises (ValueError , match = "expiry_time must be provided" ):
497+ fs .clear_expired_cache ()
498+
499+ with pytest .raises (ValueError , match = "expiry_time must be non-negative" ):
500+ fs .clear_expired_cache (expiry_time = - 1 )
501+
502+
458503def test_pop ():
459504 import tempfile
460505
0 commit comments