Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
clear photo cache when updating settings
Browse files Browse the repository at this point in the history
  • Loading branch information
himynameisjonas committed Feb 20, 2011
1 parent d5632ed commit d680615
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/admin_controller.rb
Expand Up @@ -25,6 +25,7 @@ def update
params[:setting].each do |key,value|
Setting.send("#{key}=", value)
end
Photo.clear_cache
redirect_to admin_path, :notice => "Settings saved"
end
end
9 changes: 8 additions & 1 deletion app/models/photo.rb
Expand Up @@ -9,7 +9,7 @@ def initialize(attributes = {})
end

def self.all
Rails.cache.fetch("all_photos", :expires_in => 5.minutes) do
Rails.cache.fetch(self.cache_key, :expires_in => 5.minutes) do
doc = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=#{Setting.flickr_api_key}&photoset_id=#{Setting.flickr_photoset_id}&extras=url_sq%2Curl_m%2Curl_l%2Curl_o,date_taken"))
photos = Array.new
doc.css("photo").to_a.each_index do |index|
Expand Down Expand Up @@ -49,4 +49,11 @@ def to_param
self.id
end

def self.clear_cache
Rails.cache.delete self.cache_key
end

def self.cache_key
"all_photos"
end
end

0 comments on commit d680615

Please sign in to comment.