Skip to content

Commit 74d2d59

Browse files
committed
Refactor caching mechanism to use in-memory storage only
- Removed file-based cache persistence and associated options. - Updated command-line flags to reflect changes in caching behavior. - Enhanced cache management for improved performance and simplicity.
1 parent 4ef6daa commit 74d2d59

File tree

4 files changed

+24
-101
lines changed

4 files changed

+24
-101
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Added
1313
- Static linking support for Linux environments
1414
- Performance benchmarking mode with `--benchmark` flag
15-
- Improved cache management with `--clear-cache` option
1615

1716
### Changed
17+
- Removed file-based cache persistence in favor of in-memory caching only
18+
- Removed `--cache-file` option completely
1819
- Enhanced error handling for workspace analysis
1920
- Improved progress reporting in VS Code extension
2021

bin/main.ml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ let focus_module = ref None
77
let verbose = ref false
88
let benchmark = ref false
99
let skip_cache = ref false
10-
let cache_file = ref None
1110
let clear_cache = ref false
1211

1312
let spec_list =
@@ -48,11 +47,10 @@ let spec_list =
4847
("--verbose", Arg.Set verbose, "Enable verbose output");
4948
("-b", Arg.Set benchmark, "Enable performance benchmarking");
5049
("--benchmark", Arg.Set benchmark, "Enable performance benchmarking");
51-
("--no-cache", Arg.Set skip_cache, "Skip using the cache");
52-
( "--cache-file",
53-
Arg.String (fun s -> cache_file := Some s),
54-
"Specify cache file location" );
55-
("--clear-cache", Arg.Set clear_cache, "Clear the cache before analyzing");
50+
("--no-cache", Arg.Set skip_cache, "Skip using the in-memory cache");
51+
( "--clear-cache",
52+
Arg.Set clear_cache,
53+
"Clear the in-memory cache before analyzing" );
5654
]
5755

5856
let anon_fun file = input_files := file :: !input_files
@@ -82,23 +80,15 @@ let main () =
8280

8381
time_checkpoint "Start";
8482

85-
(* Setup cache configuration *)
86-
87-
(* Set cache file if provided *)
88-
(match !cache_file with
89-
| Some path -> Rescriptdep.Parser.set_cache_file path
90-
| None ->
91-
();
92-
93-
(* Clear cache if requested *)
94-
if !clear_cache then (
95-
if !verbose then Printf.eprintf "Clearing cache\n";
96-
Rescriptdep.Parser.clear_cache ()));
83+
(* Clear in-memory cache if requested *)
84+
if !clear_cache then (
85+
if !verbose then Printf.eprintf "Clearing in-memory cache\n";
86+
Rescriptdep.Parser.clear_cache ());
9787

9888
(* Parse files and directories to get module infos *)
9989
let module_infos =
10090
if !skip_cache then (
101-
if !verbose then Printf.eprintf "Skipping cache usage\n";
91+
if !verbose then Printf.eprintf "Skipping in-memory cache usage\n";
10292
Rescriptdep.Parser.clear_cache ();
10393
Rescriptdep.Parser.parse_files_or_dirs ~verbose:!verbose
10494
~skip_cache:true !input_files)

lib/parser.ml

Lines changed: 12 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -24,75 +24,17 @@ module Cache = struct
2424
(* AST dependency check result cache *)
2525
let ast_dependency_cache = Hashtbl.create 200
2626

27-
(* Cache file path - where the cache will be stored on disk *)
28-
let cache_file = ref None
29-
30-
(* Set the cache file path *)
31-
let set_cache_file path = cache_file := Some path
32-
33-
(* Get the path of the cache file, creating default if needed *)
34-
let get_cache_file () =
35-
match !cache_file with
36-
| Some path -> path
37-
| None ->
38-
let path =
39-
Filename.concat (Sys.getcwd ()) ".rescriptdep_cache.marshal"
40-
in
41-
cache_file := Some path;
42-
path
43-
44-
(* Initialize the cache from disk if available *)
27+
(* Initialize the cache - simplified to just return false as we don't load from disk anymore *)
4528
let initialize ?(verbose = false) ?(skip_cache = false) () =
46-
(* Skip initialization if skip_cache is set *)
47-
if skip_cache then (
48-
if verbose then
49-
Printf.printf "Skip cache flag is set, not loading cache\n";
50-
false)
51-
else
52-
let path = get_cache_file () in
53-
if Sys.file_exists path then (
54-
try
55-
let ic = open_in_bin path in
56-
let stored_cache : (string, cache_entry) Hashtbl.t =
57-
Marshal.from_channel ic
58-
in
59-
close_in ic;
60-
61-
(* Transfer to our in-memory cache *)
62-
Hashtbl.iter (fun k v -> Hashtbl.replace cache_table k v) stored_cache;
63-
64-
if verbose then
65-
Printf.printf "Cache loaded from %s with %d entries\n" path
66-
(Hashtbl.length cache_table);
67-
true
68-
with e ->
69-
if verbose then
70-
Printf.printf "Error loading cache: %s\n" (Printexc.to_string e);
71-
false)
72-
else (
73-
if verbose then Printf.printf "No cache file found at %s\n" path;
74-
false)
29+
if verbose then
30+
Printf.printf "File-based caching is disabled, using only memory cache\n";
31+
false
7532

76-
(* Save the cache to disk *)
33+
(* Save the cache - simplified to just return false as we don't save to disk anymore *)
7734
let save ?(verbose = false) ?(skip_cache = false) () =
78-
(* Skip saving if skip_cache is set *)
79-
if skip_cache then (
80-
if verbose then Printf.printf "Skip cache flag is set, not saving cache\n";
81-
false)
82-
else
83-
let path = get_cache_file () in
84-
try
85-
let oc = open_out_bin path in
86-
Marshal.to_channel oc cache_table [];
87-
close_out oc;
88-
if verbose then
89-
Printf.printf "Cache saved to %s with %d entries\n" path
90-
(Hashtbl.length cache_table);
91-
true
92-
with e ->
93-
if verbose then
94-
Printf.printf "Error saving cache: %s\n" (Printexc.to_string e);
95-
false
35+
if verbose then
36+
Printf.printf "File-based caching is disabled, not saving cache to disk\n";
37+
false
9638

9739
(* Add or update an entry in the cache *)
9840
let add ?(skip_cache = false) path module_info =
@@ -892,9 +834,9 @@ let parse_files_or_dirs ?(verbose = false) ?(skip_cache = false) paths =
892834
if !benchmark then benchmark_start := Unix.gettimeofday ();
893835
bench_checkpoint "Parser started";
894836

895-
(* Initialize the cache system *)
837+
(* Initialize the memory cache system - call is kept for compatibility *)
896838
let _ = Cache.initialize ~verbose ~skip_cache () in
897-
bench_checkpoint "Cache initialization completed";
839+
bench_checkpoint "Memory cache setup completed";
898840

899841
(* Collect all cmt files *)
900842
let collect_cmt_files paths =
@@ -1021,10 +963,8 @@ let parse_files_or_dirs ?(verbose = false) ?(skip_cache = false) paths =
1021963
results)
1022964
in
1023965

1024-
(* After all files are processed, save the cache *)
1025-
let _ = bench_checkpoint "Processing completed" in
1026-
let _ = Cache.save ~verbose ~skip_cache () in
1027-
bench_checkpoint "Cache saved";
966+
(* After all files are processed, no need to save cache to disk anymore *)
967+
bench_checkpoint "Processing completed";
1028968

1029969
if !benchmark && verbose then (
1030970
Printf.eprintf "\n[PARSER-BENCH] Summary:\n";
@@ -1037,8 +977,5 @@ let parse_files_or_dirs ?(verbose = false) ?(skip_cache = false) paths =
1037977
(* Clear the module info cache *)
1038978
let clear_cache () = Cache.clear ()
1039979

1040-
(* Set the cache file path *)
1041-
let set_cache_file path = Cache.set_cache_file path
1042-
1043980
(* Set the skip cache flag - now just a stub since we pass skip_cache directly *)
1044981
let set_skip_cache _flag = ()

test/benchmark.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@ let benchmark_path =
1919
then "test/fixtures" (* Use test fixtures as fallback *)
2020
else "/tmp" (* Default to a directory that should always exist *)
2121

22-
let cache_path = "/tmp/rescriptdep_bench_cache.marshal"
23-
2422
(* Environment variables *)
2523
let () =
2624
Unix.putenv "RESCRIPTDEP_BENCHMARK" "1";
2725
Unix.putenv "RESCRIPTDEP_VERBOSE" "1"
2826

2927
let run_benchmark () =
30-
(* Set up the cache file and ensure it doesn't exist *)
31-
set_cache_file cache_path;
32-
if Sys.file_exists cache_path then Sys.remove cache_path;
28+
(* Clear memory cache to ensure fresh analysis *)
3329
clear_cache ();
3430

3531
(* Run the analysis *)
@@ -67,7 +63,6 @@ let () =
6763
exit 1);
6864

6965
Printf.printf "Running benchmark on %s\n" benchmark_path;
70-
Printf.printf "Cache file: %s\n" cache_path;
7166

7267
let _ = run_benchmark () in
7368
())

0 commit comments

Comments
 (0)