Skip to content

Commit

Permalink
Change flag name from -cache-period to -cache-lifespan (#1705)
Browse files Browse the repository at this point in the history
from 3Rafal/cache-lifespan
  • Loading branch information
voodoos authored Nov 15, 2023
2 parents e675e29 + af05ab8 commit 53eaad5
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ merlin NEXT_VERSION

+ merlin binary
- Fix a follow-up issue to the preference of non-ghost nodes introduced in #1660 (#1690, fixes #1689)
- Add `--cache-period` flag, that sets cache invalidation period. (#1698)
- Add `-cache-lifespan` flag, that sets cache invalidation period. (#1698,
#1705)
- Fix Merlin locate not fallbacking on the correct file in case of ambiguity
(@goldfirere, #1699)
+ editor modes
Expand Down
2 changes: 1 addition & 1 deletion doc/dev/CACHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ to be used anymore.
`Mocaml.flush_caches` remove all files that have changed on disk or that
haven't been used for some time. By default, `ocamlmerlin_server` remove
entries that haven't been used in the last 5 minutes. This behavior can be
changed with `--cache-period` flag.
changed with `-cache-lifespan` flag.

Since this involve stating each entry, the check is done after answering.

Expand Down
6 changes: 3 additions & 3 deletions emacs/merlin.el
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ a new window or not."
"If non-nil, use this file for the log file (should be an absolute path)."
:group 'merlin :type 'file)

(defcustom merlin-cache-period nil
(defcustom merlin-cache-lifespan nil
"If non-nil, use this value for cache period (measured in minutes)."
:group 'merlin :type 'natnum)

Expand Down Expand Up @@ -554,8 +554,8 @@ argument (lookup appropriate binary, setup logging, pass global settings)"
(cons "-flags" merlin-buffer-flags))
(when filename
(cons "-filename" filename))
(when merlin-cache-period
(cons "-cache-period" (number-to-string merlin-cache-period)))
(when merlin-cache-lifespan
(cons "-cache-lifespan" (number-to-string merlin-cache-lifespan)))
args))
;; Log last commands
(setq merlin-debug-last-commands
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/ocamlmerlin/new/new_merlin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ let run = function
Logger.with_log_file Mconfig.(config.merlin.log_file)
~sections:Mconfig.(config.merlin.log_sections) @@ fun () ->
Mocaml.flush_caches
~older_than:(float_of_int (60 * Mconfig.(config.merlin.cache_period))) ();
~older_than:(float_of_int (60 * Mconfig.(config.merlin.cache_lifespan))) ();
File_id.with_cache @@ fun () ->
let source = Msource.make (Misc.string_of_file stdin) in
let pipeline = Mpipeline.make config source in
Expand Down
10 changes: 5 additions & 5 deletions src/kernel/mconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type merlin = {
failures : string list;
extension_to_reader : (string * string) list;

cache_period : int
cache_lifespan : int
}

let dump_merlin x =
Expand Down Expand Up @@ -131,7 +131,7 @@ let dump_merlin x =
"reader", `String reader;
]) x.extension_to_reader
);
"cache_period" , Json.string (string_of_int x.cache_period)
"cache_lifespan" , Json.string (string_of_int x.cache_lifespan)
]

module Verbosity = struct
Expand Down Expand Up @@ -361,9 +361,9 @@ let merlin_flags = [
"<path> Change path of ocaml standard library"
);
(
"-cache-period",
"-cache-lifespan",
Marg.param "int" (fun prot merlin ->
try {merlin with cache_period = (int_of_string prot)}
try {merlin with cache_lifespan = (int_of_string prot)}
with _ -> invalid_arg "Valid value is int";
),
"Change file cache retention period. It's measured in minutes. \
Expand Down Expand Up @@ -638,7 +638,7 @@ let initial = {

failures = [];
extension_to_reader = [(".re","reason");(".rei","reason")];
cache_period = 5;
cache_lifespan = 5;
};
query = {
filename = "*buffer*";
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/mconfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type merlin = {

failures : string list;
extension_to_reader : (string * string) list;
cache_period : int
cache_lifespan : int
}

val dump_merlin : merlin -> json
Expand Down
2 changes: 1 addition & 1 deletion tests/test-dirs/config/dot-merlin-reader/quoting.t
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"reader": "reason"
}
],
"cache_period": "5"
"cache_lifespan": "5"
}

$ rm .merlin
6 changes: 3 additions & 3 deletions tests/test-dirs/server-tests/cache-time.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
> EOF

Let's populate file cache
$ $MERLIN server errors -log-file merlin_logs -cache-period 45 \
$ $MERLIN server errors -log-file merlin_logs -cache-lifespan 45 \
> -filename main.ml 1> /dev/null <main.ml

When cache time is set to large value, we keep the cache
$ $MERLIN server errors -log-file merlin_logs -cache-period 45 \
$ $MERLIN server errors -log-file merlin_logs -cache-lifespan 45 \
> -filename main.ml 1> /dev/null <main.ml
$ cat merlin_logs | grep -A1 "File_cache(Cmi_cache) - flush" \
> | tail -1 | sed 's/\ ".*\"//'
keeping

When cache time is set to 0, file cache gets flushed
$ $MERLIN server errors -log-file merlin_logs -cache-period 0 \
$ $MERLIN server errors -log-file merlin_logs -cache-lifespan 0 \
> -filename main.ml 1> /dev/null <main.ml
$ cat merlin_logs | grep -A1 "File_cache(Cmi_cache) - flush" \
> | tail -1 | sed 's/\ ".*\"//'
Expand Down

0 comments on commit 53eaad5

Please sign in to comment.