changeset 152:fd7344643903

Better? cache key
author nanaya <me@nanaya.pro>
date Sat, 17 Feb 2018 20:53:00 +0900
parents f0ac0c99af36
children cd76c83d6d24
files app/models/tweet.rb
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/app/models/tweet.rb	Sat Feb 17 20:45:00 2018 +0900
+++ b/app/models/tweet.rb	Sat Feb 17 20:53:00 2018 +0900
@@ -15,9 +15,13 @@
     (15 + rand(15)).minutes
   end
 
+  def cache_key
+    "timeline:v2:#{@twitter_id}/#{Base64.urlsafe_encode64 @twitter_id.to_s}"
+  end
+
   def timeline
     if @timeline.nil?
-      raw = Rails.cache.fetch("timeline:v2:#{@twitter_id}", :expires_in => cache_expires_time) do
+      raw = Rails.cache.fetch(cache_key, :expires_in => cache_expires_time) do
         client_try(:user_timeline, @twitter_id, TIMELINE_OPTIONS).tap do |data|
           if data[:result] == :ok
             if data[:data].any? && data[:data].first.user.id != @twitter_id