;run: test that demonstrates caching

This commit is contained in:
Dmitry Astapov 2025-03-06 22:09:31 +00:00 committed by Simon Michael
parent a0cf410a80
commit a3d2c7bb58
2 changed files with 17 additions and 3 deletions

View File

@ -229,14 +229,13 @@ withJournalCached defaultJournalOverride cliopts cmd = do
-- it separately.
readAndCacheJournalFile :: InputOpts -> PrefixedFilePath -> IO Journal
readAndCacheJournalFile iopts fp = do
dbg1IO "readAndCacheJournalFile" fp
modifyMVar journalCache $ \cache ->
case Map.lookup (ioptsWithoutReportSpan,fp) cache of
Just journal -> do
dbg1IO "readAndCacheJournalFile using cache" (fp, iopts)
dbg1IO ("readAndCacheJournalFile using cache for "++fp) iopts
return (cache, journal)
Nothing -> do
dbg1IO "readAndCacheJournalFile reading and caching journals" (fp, iopts)
dbg1IO ("readAndCacheJournalFile reading and caching "++fp) iopts
journal <- runExceptT $ if snd (splitReaderPrefix fp) == "-" then readStdin else readJournalFile iopts fp
either error' (\j -> return (Map.insert (ioptsWithoutReportSpan,fp) j cache, j)) journal
where

View File

@ -149,3 +149,18 @@ Assets, depth 2:
$-2 assets:cash
--------------------
$-1
# ** 0. Run caches input files, and re-parses files when InputOptions change
<
2017-01-01 groceries
assets:cash -$100
expenses:food
$ hledger run --debug 1 -f- -- accounts -- balance -f sample.journal -- balance cash --forecast -- balance cash -f sample.journal --forecast -- register -- register -f sample.journal 2>&1 | grep readAndCacheJournalFile | sed -e "s#$(pwd)/##"
>
readAndCacheJournalFile reading and caching -:
readAndCacheJournalFile using cache for -:
readAndCacheJournalFile reading and caching sample.journal:
readAndCacheJournalFile reading and caching -:
readAndCacheJournalFile reading and caching sample.journal:
readAndCacheJournalFile using cache for -:
readAndCacheJournalFile using cache for sample.journal: