Sha256: 99f7ebe94c6d153349edc9bd884e9529821cad9dd5cb0b1b4e511d9f715570db

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# dependencies
require "active_support"

# modules
require "cacheflow/version"

module Cacheflow
  def self.activate
    require "cacheflow/memcached" if defined?(Dalli)
    require "cacheflow/redis" if defined?(Redis) || defined?(RedisClient)
  end

  def self.silenced?
    Thread.current[:cacheflow_silenced]
  end

  def self.silence
    previous_value = silenced?
    begin
      Thread.current[:cacheflow_silenced] = true
      yield
    ensure
      Thread.current[:cacheflow_silenced] = previous_value
    end
  end

  def self.silence_sidekiq!
    ::Sidekiq.singleton_class.prepend(Cacheflow::Sidekiq::ClassMethods)
    ::Sidekiq::Client.prepend(Cacheflow::Sidekiq::Client::InstanceMethods)
  end

  module Sidekiq
    module ClassMethods
      def redis(*_)
        Cacheflow.silence do
          super
        end
      end
    end

    module Client
      module InstanceMethods
        def push(*_)
          Cacheflow.silence do
            super
          end
        end
      end
    end
  end
end

if defined?(Rails)
  require "cacheflow/railtie"
else
  Cacheflow.activate
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cacheflow-0.3.0 lib/cacheflow.rb