Skip to content

Commit 1205dd1

Browse files
committed
feat(fast-make): allow shared cache
One may enable the shared cache by setting the following prior to loading the fast-synthax-highlighting module ```sh typeset -gA FAST_HIGHLIGHT FAST_HIGHLIGHT[chroma-make-cache-global]=1 ``` Shared cache item is kept for 1hours. Current design expose a "flaw", where the same cached is used for any other makefile over the next hour. Still to implement: - parameterize caching timeout - introduce 1 cache items per path
1 parent 9d648cd commit 1205dd1

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

.fast-make-targets

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,23 @@ local -a TARGETS
8787
done
8888
}
8989

90-
if [[ -z "${FAST_HIGHLIGHT[chroma-make-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-make-cache-born-at] )) -gt 7 ]]; then
91-
.make-parseMakefile
92-
FAST_HIGHLIGHT[chroma-make-cache-born-at]="$EPOCHSECONDS"
93-
FAST_HIGHLIGHT[chroma-make-cache]="${(j:;:)TARGETS}"
90+
# Cache generated parsing for 1h per session or globally if configured.
91+
if [[ -n "${FAST_HIGHLIGHT[chroma-make-cache-global]}" ]]; then
92+
: "${FAST_HIGHLIGHT[chroma-make-cache-file]:="/tmp/fast-highlight-make-cache"}"
93+
: "${FAST_HIGHLIGHT[chroma-make-cache-born-at-file]:="/tmp/fast-highlight-make-cache-born-at"}"
94+
if [[ ! -f ${FAST_HIGHLIGHT[chroma-make-cache-file]} || ! -f ${FAST_HIGHLIGHT[chroma-make-cache-born-at-file]} || $(( EPOCHSECONDS - $(<"${FAST_HIGHLIGHT[chroma-make-cache-born-at-file]}") )) -gt 3600 ]]; then
95+
.make-parseMakefile
96+
print -r -- "$EPOCHSECONDS" >| "${FAST_HIGHLIGHT[chroma-make-cache-born-at-file]}"
97+
print -r -- "${(j:;:)TARGETS}" >| "${FAST_HIGHLIGHT[chroma-make-cache-file]}"
98+
fi
99+
FAST_HIGHLIGHT[chroma-make-cache]="$(<"${FAST_HIGHLIGHT[chroma-make-cache-file]}")"
100+
FAST_HIGHLIGHT[chroma-make-cache-born-at]="$(<"${FAST_HIGHLIGHT[chroma-make-cache-born-at-file]}")"
101+
else
102+
if [[ -z "${FAST_HIGHLIGHT[chroma-make-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-make-cache-born-at] )) -gt 3600 ]]; then
103+
.make-parseMakefile
104+
FAST_HIGHLIGHT[chroma-make-cache-born-at]="$EPOCHSECONDS"
105+
FAST_HIGHLIGHT[chroma-make-cache]="${(j:;:)TARGETS}"
106+
fi
94107
fi
95108

96109
reply2=( "${(s:;:)FAST_HIGHLIGHT[chroma-make-cache]}" )

0 commit comments

Comments
 (0)