From 77cd2e21b4d419a6905404c3c306f27218a87495 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Thu, 25 May 2017 13:44:03 +0200 Subject: [PATCH] Just cache '' for unchanged texts. This saves space and writing/loading times. Signed-off-by: Thomas Hochstein --- _doc/dejure/CHANGELOG | 1 + lib/filters/dejure.rb | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/_doc/dejure/CHANGELOG b/_doc/dejure/CHANGELOG index d4b30cf..039edf3 100644 --- a/_doc/dejure/CHANGELOG +++ b/_doc/dejure/CHANGELOG @@ -4,6 +4,7 @@ ### Version 0.3 (unreleased) +* Save space by caching just '' for unchanged texts. * Change protocol to https. * Make cache validity configurable. * Rename from "DejureIntegrator" to "DejureAutolinker". diff --git a/lib/filters/dejure.rb b/lib/filters/dejure.rb index fd251d4..ac40e72 100644 --- a/lib/filters/dejure.rb +++ b/lib/filters/dejure.rb @@ -124,7 +124,13 @@ module Nanoc::Filters cache_file = cache_dir + '/' + cache_filename(input) if File.directory?(cache_dir) File.open(cache_file, 'w') do |f| - f.write(output) + # if input is unchanged, just save '' + # instead of the whole (unchanged) text to save space + if input == output + f.write('') + else + f.write(output) + end end end end @@ -133,7 +139,13 @@ module Nanoc::Filters cache_file = cache_dir + '/' + cache_filename(input) # file exists and is younger than cache_days? if File.exist?(cache_file) && File.mtime(cache_file).to_i > cache_age(cache_days) - return File.read(cache_file) + output = File.read(cache_file) + # if just '' is cached, return input unchanged + if output == '' + return input + else + return output + end else return false end