From 5a0d80b781b1af238b61faea278a3c4c23b2ef46 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 15 Apr 2014 14:11:10 -0400 Subject: [PATCH] Cache: implement "dirty" attribute to only re-serialize when necessary --- lib/rscons/cache.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/rscons/cache.rb b/lib/rscons/cache.rb index a2de5ed..a9e240e 100644 --- a/lib/rscons/cache.rb +++ b/lib/rscons/cache.rb @@ -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