Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better caching to avoid hitting rate limits

  • Loading branch information...
commit b1371f4036a2c031f4b335a0aceafabac6b0f9d1 1 parent 97b07df
@mislav authored
View
2  Gemfile
@@ -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'
View
24 Gemfile.lock
@@ -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)
@@ -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)
@@ -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)
@@ -94,8 +74,6 @@ DEPENDENCIES
mongo_ext
never-forget
rake
- ruby-debug
- ruby-debug19
shotgun
sinatra
thin
View
7 app.rb
@@ -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'
@@ -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
View
8 lib/instagram/failsafe_store.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.