eBooru/app/logical/cache.rb
Earlopain 2c60ec69c8
[Prod] Replace unicorn with pitchfork
pitchfork is a unicorn fork with some things removed and some things added.
We don't need any of these things so it should be an easy replace.
There is no worker-killer for pitchfork, it is however trivial to implement ourselves.

unicorn is pretty much dead. The author implies as much in the various readme updates
he made. It also doesn't work with rack 3 and I doubt a new release will even be made.
If it will, it highly likely won't be on rubygems.
2024-05-07 21:54:25 +02:00

35 lines
876 B
Ruby

# frozen_string_literal: true
class Cache
def self.read_multi(keys, prefix)
sanitized_key_to_key_hash = keys.index_by { |key| "#{prefix}:#{key}" }
sanitized_keys = sanitized_key_to_key_hash.keys
sanitized_key_to_value_hash = Rails.cache.read_multi(*sanitized_keys)
sanitized_key_to_value_hash.transform_keys(&sanitized_key_to_key_hash)
end
def self.fetch(key, expires_in: nil, &)
Rails.cache.fetch(key, expires_in: expires_in, &)
end
def self.write(key, value, expires_in: nil)
Rails.cache.write(key, value, expires_in: expires_in)
end
def self.delete(key)
Rails.cache.delete(key)
end
def self.clear
Rails.cache.clear
end
def self.redis
# Using a shared variable like this here is OK
# since pitchfork spawns a new process for each worker
@redis ||= Redis.new(url: Danbooru.config.redis_url)
end
end