cache: replace memcache with redis.
Drop memcache. Use redis for all caching instead.
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -4,7 +4,6 @@ gem 'dotenv-rails', :require => "dotenv/rails-now"
|
||||
|
||||
gem "rails", "~> 5.2"
|
||||
gem "pg"
|
||||
gem "dalli", :platforms => :ruby
|
||||
gem "delayed_job"
|
||||
gem "delayed_job_active_record"
|
||||
gem "simple_form"
|
||||
|
||||
@@ -118,7 +118,6 @@ GEM
|
||||
safe_yaml (~> 1.0.0)
|
||||
crass (1.0.4)
|
||||
daemons (1.3.1)
|
||||
dalli (2.7.10)
|
||||
delayed_job (4.1.7)
|
||||
activesupport (>= 3.0, < 5.3)
|
||||
delayed_job_active_record (4.1.3)
|
||||
@@ -458,7 +457,6 @@ DEPENDENCIES
|
||||
capistrano3-unicorn
|
||||
cityhash
|
||||
daemons
|
||||
dalli
|
||||
delayed_job
|
||||
delayed_job_active_record
|
||||
diff-lcs
|
||||
|
||||
@@ -48,7 +48,7 @@ fi
|
||||
apt-get update
|
||||
apt-get -y install apt-transport-https
|
||||
apt-get -y install zlib1g-dev libglib2.0-dev
|
||||
apt-get -y install $LIBSSL_DEV_PKG build-essential automake libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel memcached libmemcached-dev git curl libcurl4-openssl-dev sendmail-bin sendmail nginx ssh coreutils ffmpeg mkvtoolnix
|
||||
apt-get -y install $LIBSSL_DEV_PKG build-essential automake libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel redis git curl libcurl4-openssl-dev sendmail-bin sendmail nginx ssh coreutils ffmpeg mkvtoolnix
|
||||
apt-get -y install libpq-dev postgresql-client
|
||||
apt-get -y install liblcms2-dev $LIBJPEG_TURBO_DEV_PKG libexpat1-dev libgif-dev libpng-dev libexif-dev
|
||||
|
||||
|
||||
@@ -129,11 +129,6 @@ module Danbooru
|
||||
300
|
||||
end
|
||||
|
||||
# List of memcached servers
|
||||
def memcached_servers
|
||||
%w(127.0.0.1:11211)
|
||||
end
|
||||
|
||||
# After a post receives this many comments, new comments will no longer bump the post in comment/index.
|
||||
def comment_threshold
|
||||
40
|
||||
@@ -786,6 +781,7 @@ module Danbooru
|
||||
end
|
||||
|
||||
def redis_url
|
||||
"redis://localhost:6379"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -10,11 +10,6 @@ services:
|
||||
image: redis:latest
|
||||
ports:
|
||||
- "6379:6379"
|
||||
memcached:
|
||||
image: memcached:alpine
|
||||
ports:
|
||||
- "11211:11211"
|
||||
command: memcached
|
||||
archives:
|
||||
image: r888888888/archives
|
||||
command: sleep 1d
|
||||
@@ -39,7 +34,6 @@ services:
|
||||
- RO_DATABASE_URL
|
||||
- DEBUG
|
||||
- ARCHIVE_DATABASE_URL
|
||||
- DANBOORU_MEMCACHED_SERVERS
|
||||
- DANBOORU_AWS_SQS_ARCHIVE_URL
|
||||
- DANBOORU_PIXIV_LOGIN
|
||||
- DANBOORU_PIXIV_PASSWORD
|
||||
@@ -65,6 +59,5 @@ services:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- db
|
||||
- memcached
|
||||
- archives
|
||||
- redis
|
||||
- redis
|
||||
|
||||
26
config/initializers/cache_store.rb
Normal file
26
config/initializers/cache_store.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
Rails.application.configure do
|
||||
if Rails.env.test?
|
||||
cache_config = [:memory_store, { size: 32.megabytes }]
|
||||
else
|
||||
cache_config = [
|
||||
:redis_cache_store,
|
||||
{
|
||||
url: Danbooru.config.redis_url,
|
||||
namespace: nil,
|
||||
connect_timeout: 30, # default: 20 seconds
|
||||
write_timeout: 0.2, # default: 1 second
|
||||
read_timeout: 0.2, # default: 1 second
|
||||
reconnect_attempts: 0, # default: 0
|
||||
error_handler: ->(method:, returning:, exception:) {
|
||||
DanbooruLogger.log(exception, method: method, returning: returning)
|
||||
}
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
cache_store = ActiveSupport::Cache.lookup_store(cache_config)
|
||||
|
||||
config.cache_store = cache_store
|
||||
config.action_controller.cache_store = cache_store
|
||||
Rails.cache = cache_store
|
||||
end
|
||||
@@ -1,28 +0,0 @@
|
||||
Rails.application.configure do
|
||||
begin
|
||||
if Rails.env.test?
|
||||
config.cache_store = :memory_store, { size: 32.megabytes }
|
||||
config.action_controller.cache_store = :memory_store, { size: 32.megabytes }
|
||||
Rails.cache = ActiveSupport::Cache.lookup_store(Rails.application.config.cache_store)
|
||||
else
|
||||
config.cache_store = :dalli_store, Danbooru.config.memcached_servers, { namespace: Danbooru.config.safe_app_name }
|
||||
config.action_controller.cache_store = :dalli_store, Danbooru.config.memcached_servers, { namespace: Danbooru.config.safe_app_name }
|
||||
Rails.cache = ActiveSupport::Cache.lookup_store(Rails.application.config.cache_store)
|
||||
|
||||
Rails.cache.dalli.alive!
|
||||
end
|
||||
rescue Dalli::RingError => e
|
||||
puts "-" * 40
|
||||
puts "WARNING! MEMCACHE SERVER NOT FOUND! You will experience performance degradation."
|
||||
puts e.to_s
|
||||
puts "-- BEGIN STACKTRACE --"
|
||||
e.backtrace.each do |line|
|
||||
puts line
|
||||
end
|
||||
puts "-- END STACKTRACE --"
|
||||
puts "-" * 40
|
||||
|
||||
config.cache_store = :memory_store, { size: 32.megabytes }
|
||||
Rails.cache = ActiveSupport::Cache.lookup_store(Rails.application.config.cache_store)
|
||||
end
|
||||
end
|
||||
@@ -27,7 +27,7 @@ read VLAN_IP_ADDR
|
||||
echo "* Installing packages..."
|
||||
|
||||
apt-get update
|
||||
apt-get -y install libssl-dev build-essential automake libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel memcached libmemcached-dev git curl libcurl4-openssl-dev sendmail-bin sendmail nginx ssh coreutils ffmpeg mkvtoolnix
|
||||
apt-get -y install libssl-dev build-essential automake libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel redis git curl libcurl4-openssl-dev sendmail-bin sendmail nginx ssh coreutils ffmpeg mkvtoolnix
|
||||
apt-get -y install libpq-dev postgresql-client
|
||||
apt-get -y install liblcms2-dev libjpeg-turbo8-dev libexpat1-dev libgif-dev libpng-dev libexif-dev
|
||||
|
||||
|
||||
Reference in New Issue
Block a user