M
M
Maxim Valerievich2015-06-12 21:59:11
Ruby on Rails
Maxim Valerievich, 2015-06-12 21:59:11

How to disable caching for a request in Rails?

Good day to all. I'm trying to sse, and trying to display data when the object is updated, but rails stubbornly takes the entry from the cache. How can this be prevented?

def index
    response.headers['Content-Type'] = 'text/event-stream'
    sse = SSE.new(response.stream)
    begin
      Test.on_change do |id|
        test = Test.find(id)
        t = render_to_string(partial: 'stats', formats: [:html], locals: {test: test}).gsub("\n","")
        sse.write(t)
      end
    rescue IOError
      # Client Disconnected
    ensure
      sse.close
    end
    render nothing: true
  end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
thepry, 2015-06-12
@S-anches

UPDATE: The method reloadgets the data from the cache if it is there.
1.test.reload 2
.

Test.uncached do
  Test.find(id)
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question