For our production environment, we configured in Rails (version 3.2)
config.action_controller.perform_caching = false
Oddly enough we discovered (by enabling debugging) that SQL queries where hitting the SQL cache when they were coming for a JSON request. Pages never hit the cache and the data was ok.
Does anyone know if there is some special behaviour in Rails for JSON request and SQL caching?
Also, we have config.threadsafe!
and we are using JRuby.
N.B. We tested our web pages in Chrome and Safari, both exhibit the same problem: the page itself has the right data, the JSON requests (sometimes) don't.
Note: If someone can shed light whether the QueryCache#call method is used or not in here
https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/query_cache.rb
it would be great, as it seems that it uses the cache regardless of above setting.
It may be worth mentioning that the particular issue is around a piece of code like current_user.related_object
; where the related_object
SQL result is being grabbed from the cache. current_user
is kept by devise
, the authentication gem.
Update
We have tracked the issue, and it seems the SQL cache is not being cleared properly in a multithreaded environment (again, we used JRuby). As all our pages have JSON requests, there were some connections with a not-cleared SQL cache floating around that caused issues in subsequent requests when reused.
As a workaround, we have added a before_filter
method in ApplicationController
to clear the SQL cache for the current connection.