Module: Cacheflow

Defined in:
lib/cacheflow.rb,
lib/cacheflow/redis.rb,
lib/cacheflow/sidekiq.rb,
lib/cacheflow/version.rb,
lib/cacheflow/memcached.rb

Defined Under Namespace

Modules: Memcached, Redis, Sidekiq

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.activateObject



8
9
10
11
# File 'lib/cacheflow.rb', line 8

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

.args(args) ⇒ Object

private



32
33
34
# File 'lib/cacheflow.rb', line 32

def self.args(args)
  args.map { |v| binary?(v) ? "<binary-data>" : v }.join(" ")
end

.binary?(v) ⇒ Boolean

private

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/cacheflow.rb', line 37

def self.binary?(v)
  v = v.to_s
  # string encoding creates false positives, so try to determine based on value
  v.include?("\x00") || !v.dup.force_encoding(Encoding::UTF_8).valid_encoding?
end

.silenceObject



17
18
19
20
21
22
23
24
25
# File 'lib/cacheflow.rb', line 17

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

.silence_sidekiq!Object



27
28
29
# File 'lib/cacheflow.rb', line 27

def self.silence_sidekiq!
  require_relative "cacheflow/sidekiq"
end

.silenced?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cacheflow.rb', line 13

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