2011-10-05 1 views
9

멋진 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 = trueconfig.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 
+0

글쎄, 지금은 그냥 궁극적으로이 메소드를 호출 조치에'caches_action'을 수행하기로 결정했습니다 . 당분간 잘 작동하는 것 같지만 다른 사람들이 내가 경험 한 예외에 대해 말할 필요가있는 것을 배우는 것에 관심이 있습니다. –

+0

'Rails.cache.write()'와'.read()'로 이번에 만 다시 만났습니다 : "'TypeError (는 참조 할 수 없습니다)" " –

+0

강제로해야 할 것 같은데요. 로드 될 Emlo 클래스 또는 레일스는 memcache에있는 내용을 deserialize하는 방법을 알지 못합니다. –

답변

12

이 문제는 개발 모드에서 발생 :

다음은 캐시가 가져 호출하는 방법입니다.

그러나 테스트 캐싱을 위해 개발 모드에서 config.action_controller.perform_caching을 활성화해야하는 경우 config.cache_classes도 활성화해야합니다. 하지만 이는 일시적 일 수 있습니다. 왜냐하면 자산 파이프 라인에서 클래스 나 파일을 변경 한 후에 개발 서버를 다시 시작해야하기 때문입니다.

캐싱을 사용하지 않도록 설정하면 캐싱이 발달하지 않도록 Rails.cache.write(some_name, some_value) if Rails.env.production?을 사용합니다. Rails.cache.read()은 영향을받지 않습니다.

-1

응용 프로그램의 구조에 따라이 같은 개발에 오류가 있습니다 형식 오류를 (사용자가 참조 할 수 없습니다) 이 오류는 일부 캐싱 다시로드 광기에 의해 발생합니다 : 몇 가지 보석에 의해 이식 된 미들웨어를 캐시됩니다. 그러나 개발 중에는 일반적으로 수업이 진행되지 않습니다. 따라서 일부 상황에서는 일부 수업을 사용할 수 없습니다. 일부 엔진에서 제공 한 사용자 인증을 위해 필터를 사용하기 전에 클래스 캐싱을 사용하여 위의 오류를 제거 할 수 있어야합니다. 그것을 시도 (그리고 나중에 서버를 다시 시작) :

development.rb

오류가 사라 경우, 당신은 운이 좋다

사실

config.cache_classes =. 그러나 개발시 클래스를 캐시 할 수 없기 때문에 클래스 캐싱을 다시 해제하고 참조 할 수없는 클래스를 명시 적으로 요구해야합니다. IE : development.rb의

최고

이 '응용 프로그램/모델/사용자가'필요

관련 문제