Class: ActiveRecordProxyAdapters::CacheConfiguration

Inherits:
Object
  • Object
show all
Includes:
SynchronizableConfiguration
Defined in:
lib/active_record_proxy_adapters/cache_configuration.rb

Overview

rubocop:disable Style/Documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lock = Monitor.new) ⇒ CacheConfiguration

Returns a new instance of CacheConfiguration.



22
23
24
25
26
27
# File 'lib/active_record_proxy_adapters/cache_configuration.rb', line 22

def initialize(lock = Monitor.new)
  @lock            = lock
  self.store       = ActiveSupport::Cache::NullStore.new
  self.key_prefix  = "arpa_"
  self.key_builder = ->(sql) { Digest::SHA2.hexdigest(sql) }
end

Instance Attribute Details

#key_builderProc

Returns A proc that takes an SQL statement and returns a cache key. Defaults to a SHA2 hexdigest of the SQL statement.

Returns:

  • (Proc)

    A proc that takes an SQL statement and returns a cache key. Defaults to a SHA2 hexdigest of the SQL statement.



20
21
22
# File 'lib/active_record_proxy_adapters/cache_configuration.rb', line 20

def key_builder
  @key_builder
end

#key_prefixString

Returns The prefix to use for cache keys. Defaults to “arpa_”.

Returns:

  • (String)

    The prefix to use for cache keys. Defaults to “arpa_”.



16
17
18
# File 'lib/active_record_proxy_adapters/cache_configuration.rb', line 16

def key_prefix
  @key_prefix
end

#storeActiveSupport::Cache::Store

Sets the cache store to use for caching SQL statements.

Defaults to {ActiveSupport::Cache::NullStore}, which does not cache anything.

Returns:

  • (ActiveSupport::Cache::Store)

    The cache store to use for caching SQL statements. Thread safe.



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

def store
  @store
end

Instance Method Details

#bustObject



47
48
49
# File 'lib/active_record_proxy_adapters/cache_configuration.rb', line 47

def bust
  store.delete_matched("#{key_prefix}*")
end