Ruby on rails 如何清除Rails文件缓存?
我在Ubuntu 14.04上运行Rails 4.2.7。我编写了以下方法来帮助缓存一些数据(防止对我的PostGres 9.5数据库的点击) 清除缓存并允许缓存方法正常启动的正确方法是什么 编辑:我对迪帕克的建议也有同样的错误,但这里是他的答案的输出Ruby on rails 如何清除Rails文件缓存?,ruby-on-rails,ruby-on-rails-4,caching,tmp,Ruby On Rails,Ruby On Rails 4,Caching,Tmp,我在Ubuntu 14.04上运行Rails 4.2.7。我编写了以下方法来帮助缓存一些数据(防止对我的PostGres 9.5数据库的点击) 清除缓存并允许缓存方法正常启动的正确方法是什么 编辑:我对迪帕克的建议也有同样的错误,但这里是他的答案的输出 rails@mymachine:~/myproject$ rails console Loading development environment (Rails 4.2.7.1) 2.3.0 :001 > Rails.cache.clea
rails@mymachine:~/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
在控制台中运行以下命令,而不是
rake tmp:cache:clear
Rails.cache.clear
这将从正在使用的任何缓存存储中清除缓存
config.cache_store = :file_store
# or
config.cache_store = :mem_cache_store
您的应用程序似乎需要路径
tmp/cache/001/000/
才能存在。而且,正如您在中所看到的:
,任务rake tmp:cache:clear
从tmp/cache
中删除了所有内容,包括001/000
。我想一个快速的解决方案是在清除缓存后,通过mkdir-ptmp/cache/001/000/
在项目根目录中手动创建该路径
您可以通过rails g task cache
向应用程序中添加自定义任务,并编写如下内容来实现自动化:
namespace :cache do
task :clear do
FileUtils.rm_rf(Dir['tmp/cache/[^.]*'])
`mkdir -p tmp/cache/001/000/`
end
end
然后,您可以调用自定义的
rake缓存:清除,并确保所需的路径存在。一切都取决于缓存的存储位置。检查配置文件并找到:config.cache_store,然后根据您的设置进行清理我的应用程序中没有这样的设置。在我的config/environments/proudtion.rb文件中,有一行被注释掉了,“#config.cache_store=:mem_cache_store”Deepak已经回答了您的问题,您可以尝试将iso
变量设置为integer
值吗?您在谈论什么iso变量?根据我对numBar的注释,我没有“config.cache_store”文件设置。然而,我编辑了我的qeustion以显示您的建议。在运行编辑中详细说明的命令后,我仍然会得到“nota directory@rb_file_s_rename”。请您也从development.rb或production.rb发布设置。当然,编辑了我的问题以包含config/enviornmetns/produciton.rb文件(这是一个生产环境)!!!!警告:Rails.cache.clear
不只是清除Rails缓存键。如果您的缓存是redis,并且您也在运行sidekiq,那么请与所有计划的作业、作业历史等说再见。
config.cache_store = :file_store
# or
config.cache_store = :mem_cache_store
namespace :cache do
task :clear do
FileUtils.rm_rf(Dir['tmp/cache/[^.]*'])
`mkdir -p tmp/cache/001/000/`
end
end