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