cache: replace memcache with redis.

Drop memcache. Use redis for all caching instead.
This commit is contained in:
evazion
2019-08-22 23:15:34 -05:00
parent 2e407fa476
commit dfe2b831a3
8 changed files with 30 additions and 46 deletions

View File

@@ -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

View File

@@ -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

View 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

View File

@@ -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