Make cache validity configurable.
Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
parent
cd6e7d78ad
commit
39ff33cc47
|
@ -28,9 +28,10 @@
|
||||||
#
|
#
|
||||||
# params may be set as follows:
|
# params may be set as follows:
|
||||||
# params[:format] -> [weit|schmal] (weit)
|
# params[:format] -> [weit|schmal] (weit)
|
||||||
|
# params[:buzer] -> fallback to buzer.de? (1)
|
||||||
# params[:target] -> target for <a href> ('')
|
# params[:target] -> target for <a href> ('')
|
||||||
# params[:class] -> CSS class for <a href> ('')
|
# params[:class] -> CSS class for <a href> ('')
|
||||||
# params[:buzer] -> fallback to buzer.de? (1)
|
# params[:cache_days] -> cache validity in days (7)
|
||||||
|
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'digest'
|
require 'digest'
|
||||||
|
@ -49,10 +50,15 @@ module Nanoc::Filters
|
||||||
# nothing to replace
|
# nothing to replace
|
||||||
return input
|
return input
|
||||||
end
|
end
|
||||||
|
# set cache validity in days from params or set a default
|
||||||
|
cache_days = params.delete(:cache_days)
|
||||||
|
if cache_days.nil?
|
||||||
|
cache_days = CACHEDAYS
|
||||||
|
end
|
||||||
# return output if it's already cached
|
# return output if it's already cached
|
||||||
if !(output = cache_read(input.strip))
|
if !(output = cache_read(input.strip,cache_days))
|
||||||
# purge cache if a purge is due
|
# purge cache if a purge is due
|
||||||
puts "DejureAutolinker cache purged!\n" if cache_purge
|
puts "DejureAutolinker cache purged!\n" if cache_purge(cache_days)
|
||||||
# call out to dejure.org
|
# call out to dejure.org
|
||||||
output = call_dejure(input.strip, set_params(params))
|
output = call_dejure(input.strip, set_params(params))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue