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

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