Skip to content

Commit faf319e

Browse files
committed
Fiddle with max-age to make cache more useful.
Downloading lots of items every 60s doesn't really help in development. Sometimes stale, local content is fine for extended periods.
1 parent 1031a1f commit faf319e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/nanoc/github.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,25 @@ def delete(name, options = nil)
2929
attr_reader :store
3030
end
3131

32+
class ModifyMaxAge < Faraday::Middleware
33+
def initialize(app, time:)
34+
@app = app
35+
@time = Integer(time)
36+
end
37+
38+
def call(request_env)
39+
@app.call(request_env).on_complete do |response_env|
40+
response_env[:response_headers][:cache_control] = "public, max-age=#{@time}, s-maxage=#{@time}"
41+
end
42+
end
43+
end
44+
3245
class Source < Nanoc::DataSource
3346
identifier :github
3447

3548
def up
3649
stack = Faraday::RackBuilder.new do |builder|
50+
builder.use ModifyMaxAge, time: max_age
3751
builder.use Faraday::HttpCache,
3852
serializer: Marshal,
3953
shared_cache: false,
@@ -112,6 +126,10 @@ def verbose
112126
@config[:verbose]
113127
end
114128

129+
def max_age
130+
@config[:max_age] || 60
131+
end
132+
115133
def logger
116134
Logger.new(STDOUT)
117135
end

0 commit comments

Comments
 (0)