Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
better caching to avoid hitting rate limits
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Feb 6, 2012
1 parent 97b07df commit b1371f4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Expand Up @@ -5,8 +5,6 @@ gem 'sinatra'
group :development do
gem 'shotgun'
gem 'thin'
gem 'ruby-debug', :platforms => :mri_18
gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :mri_19
end

gem 'haml'
Expand Down
24 changes: 1 addition & 23 deletions Gemfile.lock
Expand Up @@ -7,13 +7,11 @@ GEM
i18n (~> 0.4)
activesupport (3.0.5)
addressable (2.2.6)
archive-tar-minitar (0.5.2)
bson (1.4.0)
bson_ext (1.4.0)
builder (2.1.2)
choices (0.2.4)
hashie (>= 0.4.0)
columnize (0.3.2)
compass (0.10.6)
haml (>= 3.0.4)
daemons (1.1.2)
Expand All @@ -31,9 +29,6 @@ GEM
indextank (1.0.12)
faraday-stack
yajl-ruby (>= 0.7.7)
linecache (0.43)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
mingo (0.4.2)
mongo (>= 1.3)
mongo (1.4.0)
Expand All @@ -47,26 +42,11 @@ GEM
rack
rack (1.3.0)
rake (0.9.2)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-debug-base19 (0.11.24)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.4)
archive-tar-minitar (>= 0.5.2)
shotgun (0.9)
rack (>= 1.0)
sinatra (1.2.6)
rack (~> 1.1)
tilt (< 2.0, >= 1.2.2)
tilt (>= 1.2.2, < 2.0)
thin (1.2.11)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
Expand Down Expand Up @@ -94,8 +74,6 @@ DEPENDENCIES
mongo_ext
never-forget
rake
ruby-debug
ruby-debug19
shotgun
sinatra
thin
Expand Down
7 changes: 4 additions & 3 deletions app.rb
Expand Up @@ -8,6 +8,7 @@
require 'active_support/core_ext/numeric/time'
require 'active_support/core_ext/integer/time'
require 'active_support/core_ext/time/acts_like'
require 'lib/instagram/failsafe_store'
require 'addressable/uri'
require 'digest/md5'
require 'haml'
Expand Down Expand Up @@ -43,9 +44,9 @@
config.send("#{key}=", value)
end

config.cache = ActiveSupport::Cache::FileStore.new settings.cache_dir,
namespace: 'instagram',
expires_in: settings.production? ? 3.minutes : 1.hour
config.cache = Instagram::FailsafeStore.new settings.cache_dir,
namespace: 'instagram', expires_in: 20.minutes,
exceptions: %w[Faraday::Error::ClientError Timeout::Error JSON::ParserError]
end

configure :development, :production do
Expand Down
8 changes: 7 additions & 1 deletion lib/instagram/failsafe_store.rb
Expand Up @@ -46,7 +46,13 @@ def fetch(name, options = nil)
private

def ignore_exception?(ex)
options[:exceptions] && options[:exceptions].any? { |klass| ex.is_a? klass }
options[:exceptions] && options[:exceptions].any? { |klass|
if klass.respond_to?(:to_str)
ex.class.name == klass.to_str
else
ex.is_a? klass
end
}
end
end
end

0 comments on commit b1371f4

Please sign in to comment.