@@ -165,6 +165,25 @@ def load_cache(self, tables_dir=None, **kwargs):
165165 if self .offline : # In online mode, the cache tables should be downloaded later
166166 warnings .warn (f'No cache tables found in { self ._tables_dir } ' )
167167
168+ # If in remote mode and loading old tables generated on Alyx,
169+ # prompt the user to delete them to improve load times
170+ raw_meta = self ._cache ['_meta' ].get ('raw' , {}).values () or [{}]
171+ tagged = any (filter (None , flatten (x .get ('database_tags' ) for x in raw_meta )))
172+ origin = set (x ['origin' ] for x in raw_meta if 'origin' in x )
173+ older = (self ._cache ['_meta' ]['created_time' ] or datetime .now ()) < datetime (2025 , 2 , 13 )
174+ remote = not self .offline and self .mode == 'remote'
175+ if remote and origin == {'alyx' } and older and not self ._web_client .silent and not tagged :
176+ message = ('Old Alyx cache tables detected on disk. '
177+ 'It\' s recomended to remove these tables as they '
178+ 'negatively affect performance.\n Delete these tables? [Y/n]: ' )
179+ if (input (message ).casefold ().strip () or 'y' )[0 ] == 'y' :
180+ self ._remove_table_files ()
181+ self ._reset_cache ()
182+ elif len (self ._cache .datasets ) > 1e6 :
183+ warnings .warn (
184+ 'Large cache tables affect performance. '
185+ 'Consider removing them by calling the `_remove_table_files` method.' )
186+
168187 return self ._cache ['_meta' ]['loaded_time' ]
169188
170189 def save_cache (self , save_dir = None , clobber = False ):
@@ -1646,6 +1665,11 @@ def load_cache(self, tables_dir=None, clobber=False, tag=None):
16461665 tag : str
16471666 An optional Alyx dataset tag for loading cache tables containing a subset of datasets.
16481667
1668+ Returns
1669+ -------
1670+ datetime.datetime
1671+ A timestamp of when the cache was loaded.
1672+
16491673 Examples
16501674 --------
16511675 To load the cache tables for a given release tag
@@ -1669,6 +1693,8 @@ def load_cache(self, tables_dir=None, clobber=False, tag=None):
16691693 different_tag = any (x != tag for x in current_tags )
16701694 if not (clobber or different_tag ):
16711695 super (OneAlyx , self ).load_cache (tables_dir ) # Load any present cache
1696+ cache_meta = self ._cache .get ('_meta' , {})
1697+ raw_meta = cache_meta .get ('raw' , {}).values () or [{}]
16721698
16731699 try :
16741700 # Determine whether a newer cache is available
@@ -1679,15 +1705,15 @@ def load_cache(self, tables_dir=None, clobber=False, tag=None):
16791705 min_version = packaging .version .parse (cache_info .get ('min_api_version' , '0.0.0' ))
16801706 if packaging .version .parse (one .__version__ ) < min_version :
16811707 warnings .warn (f'Newer cache tables require ONE version { min_version } or greater' )
1682- return
1708+ return cache_meta [ 'loaded_time' ]
16831709
16841710 # Check whether remote cache more recent
16851711 remote_created = datetime .fromisoformat (cache_info ['date_created' ])
16861712 local_created = cache_meta .get ('created_time' , None )
16871713 fresh = local_created and (remote_created - local_created ) < timedelta (minutes = 1 )
16881714 if fresh and not different_tag :
16891715 _logger .info ('No newer cache available' )
1690- return
1716+ return cache_meta [ 'loaded_time' ]
16911717
16921718 # Set the cache table directory location
16931719 if tables_dir : # If tables directory specified, use that
@@ -1711,7 +1737,7 @@ def load_cache(self, tables_dir=None, clobber=False, tag=None):
17111737 _logger .info ('Downloading remote caches...' )
17121738 files = self .alyx .download_cache_tables (cache_info .get ('location' ), self ._tables_dir )
17131739 assert any (files )
1714- super (OneAlyx , self ).load_cache (self ._tables_dir ) # Reload cache after download
1740+ return super (OneAlyx , self ).load_cache (self ._tables_dir ) # Reload cache after download
17151741 except (requests .exceptions .HTTPError , wc .HTTPError , requests .exceptions .SSLError ) as ex :
17161742 _logger .debug (ex )
17171743 _logger .error (f'{ type (ex ).__name__ } : Failed to load the remote cache file' )
@@ -1728,6 +1754,7 @@ def load_cache(self, tables_dir=None, clobber=False, tag=None):
17281754 'Please provide valid tables_dir / cache_dir kwargs '
17291755 'or run ONE.setup to update the default directory.'
17301756 )
1757+ return cache_meta ['loaded_time' ]
17311758
17321759 @property
17331760 def alyx (self ):
0 commit comments