Just cache '<!-- idem -->' for unchanged texts.
This saves space and writing/loading times. Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
parent
c09ed68423
commit
77cd2e21b4
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
### Version 0.3 (unreleased)
|
### Version 0.3 (unreleased)
|
||||||
|
|
||||||
|
* Save space by caching just '<!-- idem -->' for unchanged texts.
|
||||||
* Change protocol to https.
|
* Change protocol to https.
|
||||||
* Make cache validity configurable.
|
* Make cache validity configurable.
|
||||||
* Rename from "DejureIntegrator" to "DejureAutolinker".
|
* Rename from "DejureIntegrator" to "DejureAutolinker".
|
||||||
|
|
|
@ -124,16 +124,28 @@ module Nanoc::Filters
|
||||||
cache_file = cache_dir + '/' + cache_filename(input)
|
cache_file = cache_dir + '/' + cache_filename(input)
|
||||||
if File.directory?(cache_dir)
|
if File.directory?(cache_dir)
|
||||||
File.open(cache_file, 'w') do |f|
|
File.open(cache_file, 'w') do |f|
|
||||||
|
# if input is unchanged, just save '<!-- idem -->'
|
||||||
|
# instead of the whole (unchanged) text to save space
|
||||||
|
if input == output
|
||||||
|
f.write('<!-- idem -->')
|
||||||
|
else
|
||||||
f.write(output)
|
f.write(output)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def cache_read (input,cache_days=CACHEDAYS,cache_dir=CACHEDIR)
|
def cache_read (input,cache_days=CACHEDAYS,cache_dir=CACHEDIR)
|
||||||
cache_file = cache_dir + '/' + cache_filename(input)
|
cache_file = cache_dir + '/' + cache_filename(input)
|
||||||
# file exists and is younger than cache_days?
|
# file exists and is younger than cache_days?
|
||||||
if File.exist?(cache_file) && File.mtime(cache_file).to_i > cache_age(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 '<!-- idem -->' is cached, return input unchanged
|
||||||
|
if output == '<!-- idem -->'
|
||||||
|
return input
|
||||||
|
else
|
||||||
|
return output
|
||||||
|
end
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue