मैं निफ्टी 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'
यह (ऊपर) के साथ लाने हमेशा विस्फोट हो जाएगा लगता है पहली कोशिश में, और उसके बाद ठीक से काम जब तक लाने समाप्ति के भीतर है । मुझे पता है कि मुझे कुछ याद आ रहा है, इसलिए आंखों की एक ताजा जोड़ी अच्छी होगी। - ऐसा लगता है ActiveRecord वस्तुओं Rails.cache
के साथ संग्रहीत नहीं किया जा सकता
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()': "टाइपरर ( को संदर्भित नहीं किया जा सकता है) ' –
लगता है जैसे आपको मजबूर होना चाहिए एम्लो वर्ग को लोड किया जाना चाहिए या अन्य रेलों को पता नहीं है कि memcache में क्या deserialize करने के लिए। –