मैं नोकोगिरी वस्तुओं को स्टोर करने के लिए रेल कैश का उपयोग करने के लिए रेल 5 का उपयोग कर रहा हूं।मैं नोकोगिरी वस्तुओं को स्टोर करने के लिए रेल कैश का उपयोग कैसे करूं?
मैं config/initializers/cache.rb में इस बनाया:
$cache = ActiveSupport::Cache::MemoryStore.new
और मैं जैसे दस्तावेज़ों को संग्रहीत करने के लिए चाहते थे:
$cache.fetch(url) {
result = get_content(url, headers, follow_redirects)
}
लेकिन मैं इस त्रुटि हो रही है:
Error during processing: (TypeError) no _dump_data is defined for class Nokogiri::HTML::Document
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:671:in `dump'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:671:in `dup_value!'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache/memory_store.rb:128:in `write_entry'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:398:in `block in write'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:562:in `block in instrument'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/notifications.rb:166:in `instrument'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:562:in `instrument'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:396:in `write'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:596:in `save_block_result_to_cache'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:300:in `fetch'
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:116:in `get_cached_content'
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:73:in `get_url'
/Users/davea/Documents/workspace/myproject/app/services/abstract_my_object_finder_service.rb:29:in `process_data'
/Users/davea/Documents/workspace/myproject/app/services/run_crawlers_service.rb:26:in `block (2 levels) in run_all_crawlers'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker'
इन वस्तुओं को कैश में स्टोर करने में सक्षम होने के लिए मुझे क्या करने की आवश्यकता है?
जाहिर है, नहीं। हालांकि, तारों को संग्रहित करने के लिए कैश अच्छा है। –
आप ऑब्जेक्ट को स्टोर क्यों करना चाहते हैं? एक क्रमबद्ध हैश या सरणी को स्टोर करें जिसमें आपने नोकोगिरी का उपयोग करके HTML या XML से स्क्रैप की जानकारी दी है। यदि आपको वस्तुओं को स्टोर करने की आवश्यकता है तो ज्ञापन में देखें। –
इस बारे में सोचकर, एक स्मृति कैश उन चीजों के लिए अच्छा है जिन्हें आपको तुरंत एक्सेस करने की आवश्यकता है, लेकिन, अगर मशीन नीचे जाती है, तो इसे जल्दी से भी बनाया जा सकता है। यदि आप नोकोगिरी का उपयोग कर रहे हैं, तो बाधाएं अच्छी हैं कि आप एक पृष्ठ को स्क्रैप कर रहे हैं, जिसका अर्थ है कि आप उस पृष्ठ को लोड कर रहे हैं, और लोड, पार्स, स्क्रैप प्रक्रिया उस विलंबता को जोड़ती है जिसे आप नहीं चाहते हैं (इसलिए कैश का उपयोग करने का विचार) , लेकिन इसके बजाय आपको अपना (मेटा) डेटा एकत्र करना चाहिए और इसे अपने डेटाबेस में संग्रहीत करना चाहिए जहां यह स्थायी रूप से उपलब्ध है। डीबीएम आंतरिक रूप से कैश करेगा। यह एक मेमोरी कैश के रूप में तेज़ नहीं है लेकिन यह अनुरोध पर या ऐप स्टार्टअप पर पुनर्निर्माण से बेहतर है। –