Class: ReactOnRailsPro::StreamCache::CachingComponent
- Inherits:
-
Object
- Object
- ReactOnRailsPro::StreamCache::CachingComponent
- Defined in:
- lib/react_on_rails_pro/stream_cache.rb
Instance Method Summary collapse
- #each_chunk(&block) ⇒ Object
-
#initialize(upstream_stream, cache_key, cache_options) ⇒ CachingComponent
constructor
A new instance of CachingComponent.
Constructor Details
#initialize(upstream_stream, cache_key, cache_options) ⇒ CachingComponent
Returns a new instance of CachingComponent.
43 44 45 46 47 |
# File 'lib/react_on_rails_pro/stream_cache.rb', line 43 def initialize(upstream_stream, cache_key, ) @upstream_stream = upstream_stream @cache_key = cache_key = end |
Instance Method Details
#each_chunk(&block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/react_on_rails_pro/stream_cache.rb', line 49 def each_chunk(&block) return enum_for(:each_chunk) unless block buffered_chunks = [] @upstream_stream.each_chunk do |chunk| buffered_chunks << chunk yield(chunk) end Rails.cache.write(@cache_key, buffered_chunks, || {}) end |