comparison app/lib/cached_fetch.rb @ 239:c800506ae799 legit-client

More varied cache period for less chance of hitting rate limit
author nanaya <me@nanaya.net>
date Sat, 15 Jul 2023 01:59:44 +0900
parents 7a773720d81f
children
comparison
equal deleted inserted replaced
238:a04b4830eef2 239:c800506ae799
10 def self.user_by_username(username) 10 def self.user_by_username(username)
11 cached("user_by_username:#{username}") { LegitClient.user_by_username(username)&.[](:user) } 11 cached("user_by_username:#{username}") { LegitClient.user_by_username(username)&.[](:user) }
12 end 12 end
13 13
14 def self.cached(key, &block) 14 def self.cached(key, &block)
15 Rails.cache.fetch(key, expires_in: (15 + rand(15)).minutes, &block) 15 Rails.cache.fetch(key, expires_in: (15 + rand(60)).minutes, &block)
16 end 16 end
17 end 17 end