@@ -684,7 +684,25 @@ def save_chart_to_base64(chart):
684684
685685
686686def build_panel_app ():
687- """Build the fiber viewer Panel app"""
687+ """
688+ Build the fiber viewer Panel app.
689+
690+ The app displays fiber implant locations for mouse subjects using data
691+ from the metadata service. Results are cached locally for fast access.
692+
693+ URL Parameters:
694+ subject_id (str): Subject identifier to load on page load
695+
696+ Admin parameters (for cache management):
697+ clear_cache=all&confirm=yes: Clears all cached procedures.
698+ Example: /fiber_viewer?clear_cache=all&confirm=yes
699+ Use when metadata service is updated and all cached data
700+ needs to be refreshed (e.g., after depth values are fixed).
701+
702+ clear_cache={subject_id}&confirm=yes: Clears cache for one subject.
703+ Example: /fiber_viewer?clear_cache=813992&confirm=yes
704+ Use to refresh data for a specific subject.
705+ """
688706
689707 # Input widgets
690708 text_input = pn .widgets .TextInput (
@@ -841,6 +859,73 @@ def copy_url_callback(event):
841859 download_button .on_click (download_callback )
842860 copy_url_button .on_click (copy_url_callback )
843861
862+ # Check for cache clearing request (admin feature)
863+ clear_cache = pn .state .location .query_params .get ("clear_cache" , "" )
864+ confirm = pn .state .location .query_params .get ("confirm" , "" )
865+
866+ if clear_cache and confirm == "yes" :
867+ try :
868+ if clear_cache == "all" :
869+ # Clear all cached procedures
870+ cache_files = list (CACHE_DIR .glob ("*.json" ))
871+ count = len (cache_files )
872+ for cache_file in cache_files :
873+ cache_file .unlink ()
874+ output_col [:] = [
875+ pn .pane .Markdown (
876+ f"**Cache cleared:** Deleted { count } cached procedure file(s). "
877+ f"All subsequent queries will fetch fresh data from metadata service." ,
878+ styles = {
879+ "background" : "#e8f5e9" ,
880+ "border-left" : "4px solid #4caf50" ,
881+ "padding" : "10px" ,
882+ "border-radius" : "5px" ,
883+ },
884+ )
885+ ]
886+ else :
887+ # Clear cache for specific subject
888+ subject_id = clear_cache
889+ cache_file = CACHE_DIR / f"{ subject_id } .json"
890+ if cache_file .exists ():
891+ cache_file .unlink ()
892+ output_col [:] = [
893+ pn .pane .Markdown (
894+ f"**Cache cleared:** Deleted cached data for subject { subject_id } . "
895+ f"Next query will fetch fresh data from metadata service." ,
896+ styles = {
897+ "background" : "#e8f5e9" ,
898+ "border-left" : "4px solid #4caf50" ,
899+ "padding" : "10px" ,
900+ "border-radius" : "5px" ,
901+ },
902+ )
903+ ]
904+ else :
905+ output_col [:] = [
906+ pn .pane .Markdown (
907+ f"**No cache found:** Subject { subject_id } has no cached data." ,
908+ styles = {
909+ "background" : "#fff8e1" ,
910+ "border-left" : "4px solid #ff9800" ,
911+ "padding" : "10px" ,
912+ "border-radius" : "5px" ,
913+ },
914+ )
915+ ]
916+ except Exception as e :
917+ output_col [:] = [
918+ pn .pane .Markdown (
919+ f"**Error clearing cache:** { str (e )} " ,
920+ styles = {
921+ "background" : "#fff5f5" ,
922+ "border-left" : "4px solid #f44336" ,
923+ "padding" : "10px" ,
924+ "border-radius" : "5px" ,
925+ },
926+ )
927+ ]
928+
844929 # Get subject_id from URL and set text input manually
845930 url_subject_id = pn .state .location .query_params .get ("subject_id" , "" )
846931 if url_subject_id :
0 commit comments