멋진 Rails.cache.fetch
을 사용하여 캐싱을 구현할 예정입니다. 그러나, 하나 개의 특정 인스턴스에서, 가끔 예외 발생 : (위로)이 항상 폭발 가져올 것Rails.cache.fetch 예외 : TypeError (<ModelName>은 참조 할 수 없습니다.)
TypeError in EmloController#index
Emlo can't be referred to
app/controllers/emlo_controller.rb:320:in `get_employees'
app/controllers/emlo_controller.rb:356:in `prepare_json_response'
app/controllers/emlo_controller.rb:23:in `block (2 levels) in index'
app/controllers/emlo_controller.rb:15:in `index'
첫 번째 시도에 한 다음 한 페치으로 잘 작동 만료 내에 . 나는 뭔가를 놓치고 있다는 것을 알기 때문에 신선한 쌍둥이가 멋질 것입니다. - 액티브 오브젝트가 Rails.cache
로 저장할 수없는 것 같다 config.action_controller.perform_caching = true
및 config.cache_classes = false
때
def get_employees
# This is for a AJAX refresh loop, so a 5-second cache actually helps quite a bit
Rails.cache.fetch('emlo_all', :expires_in => 5.seconds, :race_condition_ttl => 1) do
conditions = (params[:id]) ? {:user_id => params[:id]} : nil
selections = [
'employee_locations.id AS emlo_id',
'employee_locations.status_id',
'employee_locations.notes',
'employee_locations.until',
'employee_locations.updated_at',
'employee_locations.user_id',
'location_states.id AS state_id',
'location_states.title AS status_string',
'location_states.font_color',
'location_states.bg_color',
'users.displayname',
'users.email',
'users.mobile',
'users.department',
'users.extension',
'users.guid',
'users.dn'
].join(', ')
Emlo.all(
:select => selections,
:joins => 'LEFT JOIN users ON employee_locations.user_id=users.id LEFT JOIN location_states ON employee_locations.status_id=location_states.id',
:conditions => conditions,
:order => 'users.displayname ASC'
)
end
end
글쎄, 지금은 그냥 궁극적으로이 메소드를 호출 조치에'caches_action'을 수행하기로 결정했습니다 . 당분간 잘 작동하는 것 같지만 다른 사람들이 내가 경험 한 예외에 대해 말할 필요가있는 것을 배우는 것에 관심이 있습니다. –
'Rails.cache.write()'와'.read()'로 이번에 만 다시 만났습니다 : "'TypeError (는 참조 할 수 없습니다)" " –
강제로해야 할 것 같은데요. 로드 될 Emlo 클래스 또는 레일스는 memcache에있는 내용을 deserialize하는 방법을 알지 못합니다. –