# HG changeset patch # User edogawaconan # Date 1409931985 -32400 # Node ID 03f904c070f72504193653fc8408357b09aaebb6 # Parent efc548be0a3a71b380e75053a522fd3d79899b26 Basic caching support. diff -r efc548be0a3a -r 03f904c070f7 Gemfile --- a/Gemfile Sat Sep 06 00:08:18 2014 +0900 +++ b/Gemfile Sat Sep 06 00:46:25 2014 +0900 @@ -22,6 +22,8 @@ # Use debugger # gem 'debugger', group: [:development, :test] +# +gem "dalli" gem "twitter" gem "twitter-text" diff -r efc548be0a3a -r 03f904c070f7 Gemfile.lock --- a/Gemfile.lock Sat Sep 06 00:08:18 2014 +0900 +++ b/Gemfile.lock Sat Sep 06 00:46:25 2014 +0900 @@ -31,6 +31,7 @@ arel (5.0.1.20140414130214) buftok (0.2.0) builder (3.2.2) + dalli (2.7.2) equalizer (0.0.9) erubis (2.7.0) faraday (0.9.0) @@ -132,6 +133,7 @@ x86-mingw32 DEPENDENCIES + dalli puma rails (~> 4.1.4) sdoc (~> 0.4.0) diff -r efc548be0a3a -r 03f904c070f7 README.md --- a/README.md Sat Sep 06 00:08:18 2014 +0900 +++ b/README.md Sat Sep 06 00:46:25 2014 +0900 @@ -26,12 +26,17 @@ - `RT_CONSUMER_KEY` - `RT_CONSUMER_SECRET` +Make sure to set them before using. + Optionally, setting those two variables allows you access to private accounts which your account has access to: - `RT_ACCESS_TOKEN` - `RT_ACCESS_TOKEN_SECRET` -Make sure to set them before using. +It is also recommended to have memcached installed so tweet requests will be cached +for a short while. + +- `RT_MEMCACHED_SERVERS` (separate multiple servers with comma) License ------- diff -r efc548be0a3a -r 03f904c070f7 app/controllers/tweets_controller.rb --- a/app/controllers/tweets_controller.rb Sat Sep 06 00:08:18 2014 +0900 +++ b/app/controllers/tweets_controller.rb Sat Sep 06 00:46:25 2014 +0900 @@ -1,6 +1,7 @@ class TweetsController < ApplicationController def show @tweets = Tweet.new(params[:id]).timeline + @user = @tweets.first.user rescue Twitter::Error::NotFound head :not_found diff -r efc548be0a3a -r 03f904c070f7 app/models/tweet.rb --- a/app/models/tweet.rb Sat Sep 06 00:08:18 2014 +0900 +++ b/app/models/tweet.rb Sat Sep 06 00:46:25 2014 +0900 @@ -7,7 +7,10 @@ } def timeline - @timeline ||= @client.user_timeline(@twitter_id) + @timeline ||= + Rails.cache.fetch :timeline => @twitter_id, :expires_in => 5.minutes do + @client.user_timeline(@twitter_id) + end end def initialize(twitter_id) diff -r efc548be0a3a -r 03f904c070f7 config/application.rb --- a/config/application.rb Sat Sep 06 00:08:18 2014 +0900 +++ b/config/application.rb Sat Sep 06 00:46:25 2014 +0900 @@ -27,5 +27,9 @@ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de config.middleware.delete "ActionDispatch::Cookies" + + if ENV["RT_MEMCACHED_SERVERS"] + config.cache_store = :mem_cache_store, ENV["RT_MEMCACHED_SERVERS"].split(","), { :namespace => "rsstweet" } + end end end