Weave.jl/src/cache.jl

40 lines
1.2 KiB
Julia
Raw Normal View History

import JLD
function write_cache(doc::WeaveDoc, cache_path)
cache_dir = joinpath(doc.cwd, cache_path)
isdir(cache_dir) || mkpath(cache_dir)
JLD.save(joinpath(cache_dir, doc.basename * ".jld"), Dict("doc" => doc))
return nothing
end
function read_cache(doc::WeaveDoc, cache_path)
name = joinpath(doc.cwd, cache_path, doc.basename * ".jld")
isfile(name) || return nothing
return JLD.load(name)["doc"]
end
function restore_chunk(chunk::CodeChunk, cached)
chunks = filter(x -> x.number == chunk.number &&
string(typeof(x)) == "Weave.CodeChunk", cached.chunks)
#Chunk types, don't match after loading. Fix by constructing chunks
#from loaded content
new_chunks = Any[]
for c in chunks
newc = CodeChunk(c.content, c.number, c.start_line, c.optionstring, c.options)
newc.result_no = c.result_no
newc.figures = c.figures
newc.result = c.result
newc.output = c.output
2016-05-02 22:21:34 +02:00
newc.rich_output = c.rich_output
push!(new_chunks, newc)
end
return new_chunks
end
2015-01-08 18:35:47 +01:00
#Could be used to restore inline code in future
function restore_chunk(chunk::DocChunk, cached)
return chunk
end