2016-11-05 23 views
5

मैं उबंटू 14.04 पर रेल 4.2.7 चला रहा हूं। कैश:: मैं रेक tmp चलाने के बाद भी मदद करने के लिए कुछ डाटा को कैश (मेरी Postgres 9.5 डेटाबेस के खिलाफ हिट रोकने) निम्नलिखित विधि लिखा है ...मैं अपने रेल फ़ाइल कैश को कैसे साफ़ करूं?

class Country < ActiveRecord::Base 
    has_many :states 

    def self.cached_find_by_iso(iso) 
    Rails.cache.fetch("#{iso}") do 
     find_by_iso(iso) 
    end 
    end 

end 

हालांकि, स्पष्ट और अपने सर्वर को पुन: प्रारंभ, मैं इस त्रुटि मिल रही है जब ऊपर आह्वान करने के लिए ... प्रयास कर

Error during processing: Not a directory @ rb_file_s_rename - (/home/rails/myproject/tmp/cache/00020161104-1093-67j634, /home/rails/myproject/tmp/cache/001/000/) 
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:528:in `rename' 
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:528:in `block in mv' 
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:1571:in `block in fu_each_src_dest' 
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:1587:in `fu_each_src_dest0' 
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:1569:in `fu_each_src_dest' 
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:517:in `mv' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/file/atomic.rb:36:in `atomic_write' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache/file_store.rb:83:in `write_entry' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache/strategy/local_cache.rb:115:in `write_entry' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:391:in `block in write' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:547:in `block in instrument' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/notifications.rb:166:in `instrument' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:547:in `instrument' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:389:in `write' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:588:in `save_block_result_to_cache' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:299:in `fetch' 
/home/rails/myproject/app/models/country.rb:5:in `cached_find_by_iso' 
/home/rails/myproject/app/services/all_events_guide_service.rb:84:in `block in process_page_data' 
/usr/local/rvm/gems/ruby-2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:187:in `block in each' 
/usr/local/rvm/gems/ruby-2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:186:in `upto' 
/usr/local/rvm/gems/ruby-2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:186:in `each' 
/home/rails/myproject/app/services/all_events_guide_service.rb:45:in `process_page_data' 
/home/rails/myproject/app/services/abstract_import_service.rb:83:in `process_my_object_data' 
/home/rails/myproject/app/services/all_events_guide_my_object_finder_service.rb:103:in `block in process_my_object_link' 
/usr/local/rvm/gems/ruby-2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:187:in `block in each' 
/usr/local/rvm/gems/ruby-2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:186:in `upto' 
/usr/local/rvm/gems/ruby-2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:186:in `each' 
/home/rails/myproject/app/services/all_events_guide_my_object_finder_service.rb:82:in `process_my_object_link' 
/home/rails/myproject/app/services/abstract_my_object_finder_service.rb:29:in `block in process_data' 
/home/rails/myproject/app/services/abstract_my_object_finder_service.rb:28:in `each' 
/home/rails/myproject/app/services/abstract_my_object_finder_service.rb:28:in `process_data' 
/home/rails/myproject/app/services/run_crawlers_service.rb:18:in `block in run_all_crawlers' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each' 
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each' 
/home/rails/myproject/app/services/run_crawlers_service.rb:5:in `run_all_crawlers' 
/home/rails/myproject/app/controllers/my_objects_controller.rb:170:in `block in import' 

मेरी कैश साफ़ करें और मेरी कैश्ड विधि ठीक से काम शुरू करने के लिए अनुमति देने के लिए सही तरीका क्या है?

संपादित करें: मैं दीपक के सुझाव के साथ एक ही ऊपर त्रुटि मिलती है, लेकिन यहाँ अपने जवाब देने के लिए उत्पादन है ...

[email protected]:~/myproject$ rails console 
Loading development environment (Rails 4.2.7.1) 
2.3.0 :001 > Rails.cache.clear 
=> ["/home/rails/myproject/tmp/cache/assets"] 
2.3.0 :002 > quit 

संपादित करें 2: यहाँ मेरी config/environments.production.rb है फ़ाइल। यह एक उत्पादन वातावरण

Rails.application.configure do 
    # Settings specified here will take precedence over those in config/application.rb. 

    # Code is not reloaded between requests. 
    config.cache_classes = true 

    # Eager load code on boot. This eager loads most of Rails and 
    # your application in memory, allowing both threaded web servers 
    # and those relying on copy on write to perform better. 
    # Rake tasks automatically ignore this option for performance. 
    config.eager_load = true 

    # Full error reports are disabled and caching is turned on. 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 

    # Enable Rack::Cache to put a simple HTTP cache in front of your application 
    # Add `rack-cache` to your Gemfile before enabling this. 
    # For large-scale production use, consider using a caching reverse proxy like 
    # NGINX, varnish or squid. 
    # config.action_dispatch.rack_cache = true 

    # Disable serving static files from the `/public` folder by default since 
    # Apache or NGINX already handles this. 
    config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 

    # Compress JavaScripts and CSS. 
    config.assets.js_compressor = :uglifier 
    # config.assets.css_compressor = :sass 

    # Do not fallback to assets pipeline if a precompiled asset is missed. 
    config.assets.compile = false 

    # Asset digests allow you to set far-future HTTP expiration dates on all assets, 
    # yet still be able to expire them through the digest params. 
    config.assets.digest = true 

    # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 

    # Specifies the header that your server uses for sending files. 
    # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 

    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 
    # config.force_ssl = true 

    # Use the lowest log level to ensure availability of diagnostic information 
    # when problems arise. 
    config.log_level = :debug 

    # Prepend all log lines with the following tags. 
    # config.log_tags = [ :subdomain, :uuid ] 

    # Use a different logger for distributed setups. 
    # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 

    # Use a different cache store in production. 
    # config.cache_store = :mem_cache_store 

    # Enable serving of images, stylesheets, and JavaScripts from an asset server. 
    # config.action_controller.asset_host = 'http://assets.example.com' 

    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 
    # the I18n.default_locale when a translation cannot be found). 
    config.i18n.fallbacks = true 

    # Send deprecation notices to registered listeners. 
    config.active_support.deprecation = :notify 

    # Use default logging formatter so that PID and timestamp are not suppressed. 
    config.log_formatter = ::Logger::Formatter.new 

    # Do not dump schema after migrations. 
    config.active_record.dump_schema_after_migration = false 

    config.serve_static_assets = true 
    config.assets.compile = true 
end 
+0

सब कुछ इस बात पर निर्भर करता है कि आप अपना कैश कहां स्टोर करते हैं। कॉन्फ़िगरेशन फ़ाइलों की जांच करें और ढूंढें: config.cache_store और फिर अपनी सेटिंग्स के अनुसार सफाई करें – num8er

+0

मेरे पास मेरे ऐपिकेशन में कहीं भी ऐसी कोई सेटिंग नहीं है। मेरी कॉन्फ़िगरेशन/वातावरण/गर्वशन.आरबी फ़ाइल में, लाइन पर टिप्पणी की गई है, "# config.cache_store =: mem_cache_store" – Dave

+0

दीपक ने आपके प्रश्न का उत्तर दिया है – num8er

उत्तर

12

के बजाय rake tmp:cache:clear कंसोल में निम्न आदेश

Rails.cache.clear 

इस से संचय साफ हो जाएगा चलाने है ... जो कुछ भी कैश की दुकान आप उपयोग कर रहे

config.cache_store = :file_store 
# or 
config.cache_store = :mem_cache_store 
+0

numBar पर मेरी टिप्पणी के अनुसार, मेरे पास कोई "config.cache_store" फ़ाइल सेटिंग नहीं है। हालांकि, मैंने आपके सुझाव को दिखाने के लिए अपना क्यूस्टियन संपादित किया। संपादन में विस्तृत आदेशों को चलाने के बाद भी मुझे "निर्देशिका नहीं है @ rb_file_s_rename"। – Dave

+0

क्या आप कृपया अपने विकास.आरबी या उत्पादन.आरबी –

+0

से सेटिंग पोस्ट कर सकते हैं, निश्चित रूप से, कॉन्फ़िगर/enviornmetns/produciton.rb फ़ाइल को शामिल करने के लिए मेरे प्रश्न को संपादित किया गया (यह एक उत्पादन वातावरण है) – Dave

1

ऐसा लगता है आपके आवेदन की तरह किसी भी तरह से tmp/cache/001/000/ पथ मौजूद होना आवश्यक है। और, जैसा कि आप देख सकते हैं: https://github.com/rails/rails/blob/4-2-stable/railties/lib/rails/tasks/tmp.rake#L25-L30, कार्य rake tmp:cache:clear से 001/000 सहित सभी सामग्री हटा दी गई है। मुझे लगता है कि आपके कैश को साफ़ करने के बाद अपने प्रोजेक्ट रूट के अंदर mkdir -p tmp/cache/001/000/ द्वारा उस पथ को मैन्युअल रूप से बनाने का एक त्वरित समाधान होगा।

namespace :cache do 
    task :clear do 
    FileUtils.rm_rf(Dir['tmp/cache/[^.]*']) 
    `mkdir -p tmp/cache/001/000/` 
    end 
end 

तब आप अपने कस्टम rake cache:clear आह्वान और यह सुनिश्चित करें कि मांग की पथ मौजूद हो सकता है:

तुम कुछ लिखने जैसा rails g task cache द्वारा अपने आवेदन इस स्वचालित करने के लिए एक कस्टम कार्य जोड़ने और सकता है।

संबंधित मुद्दे