From 78484b8fd325c14bc9b5ea96ebe106a7d602c78e Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Thu, 24 Nov 2011 14:14:06 +0400 Subject: [PATCH] Varnish caching for artist data and lastfm suggest --- app/assets/javascripts/search.coffee | 2 +- app/controllers/artist_controller.rb | 1 + app/controllers/last_fm_controller.rb | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/search.coffee b/app/assets/javascripts/search.coffee index d9d8807..bfb4aab 100644 --- a/app/assets/javascripts/search.coffee +++ b/app/assets/javascripts/search.coffee @@ -64,4 +64,4 @@ $('#search-form').live 'submit', -> false $('.data.artist').live 'click', -> _search.loadArtistData $(this).html() - false \ No newline at end of file + false diff --git a/app/controllers/artist_controller.rb b/app/controllers/artist_controller.rb index 9c69ef9..e6525fd 100644 --- a/app/controllers/artist_controller.rb +++ b/app/controllers/artist_controller.rb @@ -32,6 +32,7 @@ class ArtistController < ApplicationController return render json: { status: 'fail', html: render_compact_partial(:fail) } end + response.headers['Cache-Control'] = 'public, max-age='+1.week.seconds.to_s render json: { status: @artist.status_str, artist: @artist, diff --git a/app/controllers/last_fm_controller.rb b/app/controllers/last_fm_controller.rb index a3ed906..e84dff0 100644 --- a/app/controllers/last_fm_controller.rb +++ b/app/controllers/last_fm_controller.rb @@ -86,6 +86,8 @@ class LastFmController < ApplicationController autocomplete["response"]["docs"].each do |doc| suggestions << doc["artist"] unless suggestions.include?(doc["artist"]) or doc["artist"].nil? or doc['restype'] != 6 end + + response.headers['Cache-Control'] = 'public, max-age='+1.week.seconds.to_s render :json => { :query => params[:query], :suggestions => suggestions.take(5)