Cache: implement "dirty" attribute to only re-serialize when necessary

This commit is contained in:
Josh Holtrop 2014-04-15 14:11:10 -04:00
parent a2653a77d1
commit 5a0d80b781

View File

@ -75,10 +75,13 @@ module Rscons
# Write the cache to disk to be loaded next time.
def write
@cache["version"] = VERSION
File.open(CACHE_FILE, "w") do |fh|
fh.puts(JSON.dump(@cache))
if @dirty || (@cache["version"] != VERSION)
@cache["version"] = VERSION
File.open(CACHE_FILE, "w") do |fh|
fh.puts(JSON.dump(@cache))
end
end
@dirty = false
end
# Check if target(s) are up to date
@ -164,6 +167,7 @@ module Rscons
}
end,
}
@dirty = true
end
end
@ -181,6 +185,7 @@ module Rscons
unless File.exists?(subpath)
FileUtils.mkdir(subpath)
@cache["directories"][subpath] = true
@dirty = true
end
end
end
@ -203,6 +208,7 @@ module Rscons
@cache["targets"] ||= {}
@cache["directories"] ||= {}
@lookup_checksums = {}
@dirty = false
end
# Return a file's checksum, or the previously calculated checksum for