Skip to content

Commit 0b23476

Browse files
committed
Homeland::ImageThumb 支持 HTTP Request Headers Pragma: no-cache
1 parent eebdf60 commit 0b23476

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

app/controllers/home_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def uploads
1212
# DO NOT use this in production environment.
1313
format, version = params[:format].split("!")
1414
filename = [params[:path], format].join(".")
15-
thumb = Homeland::ImageThumb.new(filename, version)
15+
pragma = request.headers['Pragma'] == 'no-cache'
16+
thumb = Homeland::ImageThumb.new(filename, version, pragma: pragma)
1617
send_file thumb.outpath, type: 'image/jpeg', disposition: 'inline'
1718
end
1819

lib/homeland/image_thumb.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ class ImageThumb
88
attr_reader :filename
99
attr_reader :version
1010

11-
def initialize(filename, version)
11+
def initialize(filename, version, pragma: false)
1212
@filename = filename
1313
@version = version
1414
@outpath = Rails.root.join('tmp', 'cache', 'uploads-thumb', "#{filename}-#{version}")
1515

16-
generate! unless File.exists? outpath
16+
notfound = !File.exists?(outpath)
17+
generate! if pragma || notfound
1718
end
1819

1920
private

0 commit comments

Comments
 (0)