Mercurial > rsstweet
annotate app/lib/cached_fetch.rb @ 254:89f6c0016bab default tip
Update to latest rails
author | nanaya <me@nanaya.net> |
---|---|
date | Tue, 03 Sep 2024 19:21:25 +0900 |
parents | c800506ae799 |
children |
rev | line source |
---|---|
234 | 1 module CachedFetch |
2 def self.timeline(user_id) | |
3 cached("timeline:#{user_id}") { LegitClient.timeline(user_id)&.[](:timeline) } | |
4 end | |
5 | |
6 def self.user_by_id(user_id) | |
7 cached("user_by_id:#{user_id}") { LegitClient.user_by_id(user_id)&.[](:user) } | |
8 end | |
9 | |
10 def self.user_by_username(username) | |
11 cached("user_by_username:#{username}") { LegitClient.user_by_username(username)&.[](:user) } | |
12 end | |
13 | |
14 def self.cached(key, &block) | |
239
c800506ae799
More varied cache period for less chance of hitting rate limit
nanaya <me@nanaya.net>
parents:
234
diff
changeset
|
15 Rails.cache.fetch(key, expires_in: (15 + rand(60)).minutes, &block) |
234 | 16 end |
17 end |