Module: SecondLevelCache

Defined in:
lib/second_level_cache.rb,
lib/second_level_cache/mixin.rb,
lib/second_level_cache/config.rb,
lib/second_level_cache/version.rb,
lib/second_level_cache/log_subscriber.rb,
lib/second_level_cache/record_relation.rb,
lib/second_level_cache/adapter/paranoia.rb,
lib/second_level_cache/active_record/base.rb,
lib/second_level_cache/active_record/core.rb,
lib/second_level_cache/active_record/persistence.rb,
lib/second_level_cache/active_record/finder_methods.rb,
lib/second_level_cache/active_record/preloader/legacy.rb,
lib/second_level_cache/active_record/fetch_by_uniq_key.rb,
lib/second_level_cache/active_record/has_one_association.rb,
lib/second_level_cache/active_record/preloader/association.rb,
lib/second_level_cache/active_record/belongs_to_association.rb

Defined Under Namespace

Modules: ActiveRecord, Adapter, Mixin Classes: Config, LogSubscriber, RecordRelation

Constant Summary collapse

VERSION =
"2.7.1"

Class Method Summary collapse

Class Method Details

.cache_enabled=(cache_enabled) ⇒ Object



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

def self.cache_enabled=(cache_enabled)
  Thread.current[:slc_cache_enabled] = cache_enabled
end

.cache_enabled?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/second_level_cache.rb', line 24

def self.cache_enabled?
  if self.cache_store.is_a?(ActiveSupport::Cache::NullStore)
    return false
  end
  cache_enabled = Thread.current[:slc_cache_enabled]
  cache_enabled.nil? ? true : cache_enabled
end

.configureObject



11
12
13
# File 'lib/second_level_cache.rb', line 11

def self.configure
  block_given? ? yield(Config) : Config
end

.without_second_level_cacheObject



15
16
17
18
19
20
21
22
# File 'lib/second_level_cache.rb', line 15

def self.without_second_level_cache
  old_cache_enabled = SecondLevelCache.cache_enabled?
  SecondLevelCache.cache_enabled = false

  yield
ensure
  SecondLevelCache.cache_enabled = old_cache_enabled
end