@@ -372,6 +372,68 @@ def get_items_hashes(func, items=None):
372372 # bug fixed, which causes bad cached items order
373373 return [Cache .hash (item ) for item in items ]
374374
375+ @staticmethod
376+ def _get_cache_modified_time (func , key_data ):
377+ """
378+ Private function to get the timestamp when cache was stored.
379+ Returns the modification time of the cache file as a datetime object.
380+ """
381+ from datetime import datetime
382+
383+ _create_cache_directory_if_not_exists (func )
384+ path = _get_cache_path (func , key_data )
385+
386+ if not _has (path ):
387+ raise CacheMissException (path )
388+
389+ # Get file modification time
390+ timestamp = os .path .getmtime (path )
391+ return datetime .fromtimestamp (timestamp )
392+
393+ @staticmethod
394+ def is_cache_older_than (func , key_data , days = 0 , seconds = 0 , microseconds = 0 ,
395+ milliseconds = 0 , minutes = 0 , hours = 0 , weeks = 0 ):
396+ """
397+ Check if cached item is older than the specified time period.
398+
399+ Args:
400+ func: The function name or object
401+ key_data: The cache key
402+ days: Number of days (default: 0)
403+ seconds: Number of seconds (default: 0)
404+ microseconds: Number of microseconds (default: 0)
405+ milliseconds: Number of milliseconds (default: 0)
406+ minutes: Number of minutes (default: 0)
407+ hours: Number of hours (default: 0)
408+ weeks: Number of weeks (default: 0)
409+
410+ Returns:
411+ bool: True if cache is older than specified time period, False otherwise
412+
413+ Raises:
414+ CacheMissException: If cache doesn't exist
415+ """
416+ from datetime import datetime , timedelta
417+
418+ # Create timedelta from parameters
419+ time_delta = timedelta (
420+ days = days ,
421+ seconds = seconds ,
422+ microseconds = microseconds ,
423+ milliseconds = milliseconds ,
424+ minutes = minutes ,
425+ hours = hours ,
426+ weeks = weeks
427+ )
428+
429+ # Get cache timestamp
430+ cache_time = Cache ._get_cache_modified_time (func , key_data )
431+
432+ # Compare with current time
433+ age = datetime .now () - cache_time
434+
435+ return age > time_delta
436+
375437 @staticmethod
376438 def delete (func , key_data ):
377439 """Remove a specific cache file."""
0 commit comments