@@ -78,14 +78,31 @@ async function loadAllStatusesFallback() {
7878
7979/**
8080 * Legacy: Load CLI tool status individually
81+ * 优先从缓存读取,如果缓存有效则直接使用
8182 */
8283async function loadCliToolStatus ( ) {
84+ // 尝试从缓存获取
85+ if ( window . cacheManager ) {
86+ const cached = window . cacheManager . get ( 'cli-status' ) ;
87+ if ( cached ) {
88+ cliToolStatus = cached ;
89+ updateCliBadge ( ) ;
90+ console . log ( '[CLI Status] Loaded from cache' ) ;
91+ return cached ;
92+ }
93+ }
94+
8395 try {
8496 const response = await fetch ( '/api/cli/status' ) ;
8597 if ( ! response . ok ) throw new Error ( 'Failed to load CLI status' ) ;
8698 const data = await response . json ( ) ;
8799 cliToolStatus = data ;
88100
101+ // 存入缓存
102+ if ( window . cacheManager ) {
103+ window . cacheManager . set ( 'cli-status' , data , 300000 ) ; // 5分钟
104+ }
105+
89106 // Update badge
90107 updateCliBadge ( ) ;
91108
@@ -135,36 +152,31 @@ async function loadCodexLensStatus() {
135152/**
136153 * Load CodexLens dashboard data using aggregated endpoint (single API call)
137154 * This is optimized for the CodexLens Manager page initialization
155+ * 优先从缓存读取,如果缓存有效则直接使用
138156 * @returns {Promise<object|null> } Dashboard init data or null on error
139157 */
140158async function loadCodexLensDashboardInit ( ) {
159+ // 尝试从缓存获取
160+ if ( window . cacheManager ) {
161+ const cached = window . cacheManager . get ( 'dashboard-init' ) ;
162+ if ( cached ) {
163+ applyDashboardInitData ( cached ) ;
164+ console . log ( '[CLI Status] CodexLens dashboard init loaded from cache' ) ;
165+ return cached ;
166+ }
167+ }
168+
141169 try {
142170 const response = await fetch ( '/api/codexlens/dashboard-init' ) ;
143171 if ( ! response . ok ) throw new Error ( 'Failed to load CodexLens dashboard init' ) ;
144172 const data = await response . json ( ) ;
145173
146- // Update status variables from aggregated response
147- codexLensStatus = data . status || { ready : false } ;
148- semanticStatus = data . semantic || { available : false } ;
174+ applyDashboardInitData ( data ) ;
149175
150- // Expose to window for other modules
151- if ( ! window . cliToolsStatus ) {
152- window . cliToolsStatus = { } ;
176+ // 存入缓存
177+ if ( window . cacheManager ) {
178+ window . cacheManager . set ( 'dashboard-init' , data , 300000 ) ; // 5分钟
153179 }
154- window . cliToolsStatus . codexlens = {
155- installed : data . installed || false ,
156- version : data . status ?. version || null ,
157- installedModels : [ ] ,
158- config : data . config || { } ,
159- semantic : data . semantic || { }
160- } ;
161-
162- // Store config globally for easy access
163- window . codexLensConfig = data . config || { } ;
164- window . codexLensStatusData = data . statusData || { } ;
165-
166- // Update badges
167- updateCodexLensBadge ( ) ;
168180
169181 console . log ( '[CLI Status] CodexLens dashboard init loaded:' , {
170182 installed : data . installed ,
@@ -180,6 +192,35 @@ async function loadCodexLensDashboardInit() {
180192 }
181193}
182194
195+ /**
196+ * 应用 dashboard-init 数据到状态变量
197+ * @param {object } data - dashboard init 响应数据
198+ */
199+ function applyDashboardInitData ( data ) {
200+ // Update status variables from aggregated response
201+ codexLensStatus = data . status || { ready : false } ;
202+ semanticStatus = data . semantic || { available : false } ;
203+
204+ // Expose to window for other modules
205+ if ( ! window . cliToolsStatus ) {
206+ window . cliToolsStatus = { } ;
207+ }
208+ window . cliToolsStatus . codexlens = {
209+ installed : data . installed || false ,
210+ version : data . status ?. version || null ,
211+ installedModels : [ ] ,
212+ config : data . config || { } ,
213+ semantic : data . semantic || { }
214+ } ;
215+
216+ // Store config globally for easy access
217+ window . codexLensConfig = data . config || { } ;
218+ window . codexLensStatusData = data . statusData || { } ;
219+
220+ // Update badges
221+ updateCodexLensBadge ( ) ;
222+ }
223+
183224/**
184225 * Legacy: Load semantic status individually
185226 */
@@ -229,8 +270,23 @@ async function loadInstalledModels() {
229270
230271/**
231272 * Load CLI tools config from .claude/cli-tools.json (project or global fallback)
273+ * 优先从缓存读取,如果缓存有效则直接使用
232274 */
233275async function loadCliToolsConfig ( ) {
276+ // 尝试从缓存获取
277+ if ( window . cacheManager ) {
278+ const cached = window . cacheManager . get ( 'cli-tools-config' ) ;
279+ if ( cached ) {
280+ cliToolsConfig = cached . tools ?. tools || { } ;
281+ window . claudeCliToolsConfig = cached ;
282+ if ( cached . defaultTool ) {
283+ defaultCliTool = cached . defaultTool ;
284+ }
285+ console . log ( '[CLI Tools Config] Loaded from cache' ) ;
286+ return cached ;
287+ }
288+ }
289+
234290 try {
235291 const response = await fetch ( '/api/cli/tools-config' ) ;
236292 if ( ! response . ok ) return null ;
@@ -244,6 +300,11 @@ async function loadCliToolsConfig() {
244300 defaultCliTool = data . defaultTool ;
245301 }
246302
303+ // 存入缓存
304+ if ( window . cacheManager ) {
305+ window . cacheManager . set ( 'cli-tools-config' , data , 300000 ) ; // 5分钟
306+ }
307+
247308 console . log ( '[CLI Config] Loaded from:' , data . _configInfo ?. source || 'unknown' , '| Default:' , data . defaultTool ) ;
248309 return data ;
249310 } catch ( err ) {
0 commit comments