2
Rails.cache(memory_store)を使用してユーザーのオンライン/オフラインリストを維持したいと考えています。rails:Rails.cacheからすべてのキー値を取得する方法
要求/user/heartbeat?name=John
はRailsのサーバーに到達し、それは単純になります基本的には場合:
def update_status
name = params.require(:name)
Rails.cache.write(name, Time.now.utc.iso8601, expires_in: 6.seconds)
end
しかし、私は、次のと同様Rails.cacheに格納されているすべてのデータを得ることができますか?
def get_status
# wrong codes, as Rails.cache.read doesn't have :all option.
ary = Rails.cache.read(:all)
# deal with array ...
end
私はしばらくの間googled、Rails.cacheはすべてのデータを直接取得する方法を提供していないようです。または、データを保存するためのよりよい方法がありますか?
私はRails 5.0.2
を使用しています。
ありがとうございました!