@@ -16,6 +16,11 @@ local config = {}
1616local project_root_cache = {}
1717local cache_expiry = {}
1818
19+ -- Cache for marks file
20+ local marks_cache = nil
21+ local marks_cache_timestamp = nil
22+ local marks_cache_project = nil
23+
1924--- Helper function for conditional notifications
2025--- @param message string The notification message
2126--- @param level number The log level
@@ -202,12 +207,23 @@ local function validate_marks_data(data)
202207 return true
203208end
204209
205- --- Load marks from storage file
210+ --- Load marks from storage file with caching
206211--- @return table marks The loaded marks
207212local function load_marks ()
208213 current_project = get_project_root ()
209214 local file = get_marks_file ()
210215
216+ -- Check cache validity
217+ if marks_cache and marks_cache_project == current_project then
218+ local file_mtime = vim .fn .getftime (file )
219+ if file_mtime > 0 and marks_cache_timestamp == file_mtime then
220+ -- Cache is valid, return cached data
221+ marks = marks_cache .marks
222+ mark_order = marks_cache .mark_order
223+ return marks
224+ end
225+ end
226+
211227 -- Initialize empty state
212228 marks = {}
213229 mark_order = {}
@@ -246,6 +262,14 @@ local function load_marks()
246262 end
247263 end
248264 mark_order = valid_order
265+
266+ -- Update cache
267+ marks_cache = {
268+ marks = vim .deepcopy (marks ),
269+ mark_order = vim .deepcopy (mark_order ),
270+ }
271+ marks_cache_timestamp = vim .fn .getftime (file )
272+ marks_cache_project = current_project
249273 end
250274 end
251275 end
@@ -325,6 +349,14 @@ function M.save_marks()
325349 if not rename_ok then
326350 error (" Failed to move temporary file to final location" )
327351 end
352+
353+ -- Update cache after successful save
354+ marks_cache = {
355+ marks = vim .deepcopy (marks ),
356+ mark_order = vim .deepcopy (mark_order ),
357+ }
358+ marks_cache_timestamp = vim .fn .getftime (file )
359+ marks_cache_project = current_project
328360 end )
329361
330362 if not ok then
@@ -409,6 +441,10 @@ function M.add_mark(name, mark)
409441 end
410442
411443 marks_data [name ] = mark
444+
445+ -- Invalidate cache for immediate update
446+ marks_cache = nil
447+
412448 return true -- Save is handled by debounced save in main module
413449end
414450
@@ -429,6 +465,9 @@ function M.delete_mark(name)
429465 end
430466 end
431467
468+ -- Invalidate cache
469+ marks_cache = nil
470+
432471 return true
433472 end
434473
@@ -466,6 +505,9 @@ function M.rename_mark(old_name, new_name)
466505 end
467506 end
468507
508+ -- Invalidate cache
509+ marks_cache = nil
510+
469511 return true
470512end
471513
@@ -505,6 +547,9 @@ function M.move_mark(name, direction)
505547 -- Swap positions
506548 mark_order [current_index ], mark_order [new_index ] = mark_order [new_index ], mark_order [current_index ]
507549
550+ -- Invalidate cache
551+ marks_cache = nil
552+
508553 return true
509554end
510555
513558function M .clear_all_marks ()
514559 marks = {}
515560 mark_order = {}
561+
562+ -- Invalidate cache
563+ marks_cache = nil
564+
516565 return true
517566end
518567
@@ -628,6 +677,9 @@ function M.import_marks()
628677 return { success = false , message = " Import cancelled" }
629678 end
630679
680+ -- Invalidate cache
681+ marks_cache = nil
682+
631683 if M .save_marks () then
632684 notify (" Marks imported successfully" , vim .log .levels .INFO )
633685 return { success = true , message = " Marks imported successfully" }
@@ -665,6 +717,9 @@ function M.cleanup()
665717 -- Clear caches
666718 project_root_cache = {}
667719 cache_expiry = {}
720+ marks_cache = nil
721+ marks_cache_timestamp = nil
722+ marks_cache_project = nil
668723
669724 -- Reset state
670725 marks = {}
0 commit comments