Mercurial > rsstweet
view app/lib/cached_fetch.rb @ 261:8c47a69cbfdb
Missing default 8.0 bin
author | nanaya <me@nanaya.net> |
---|---|
date | Sun, 15 Dec 2024 23:01:58 +0900 |
parents | c800506ae799 |
children |
line wrap: on
line source
module CachedFetch def self.timeline(user_id) cached("timeline:#{user_id}") { LegitClient.timeline(user_id)&.[](:timeline) } end def self.user_by_id(user_id) cached("user_by_id:#{user_id}") { LegitClient.user_by_id(user_id)&.[](:user) } end def self.user_by_username(username) cached("user_by_username:#{username}") { LegitClient.user_by_username(username)&.[](:user) } end def self.cached(key, &block) Rails.cache.fetch(key, expires_in: (15 + rand(60)).minutes, &block) end end