Class: ActiveRecordProxyAdapters::CacheConfiguration
- Inherits:
-
Object
- Object
- ActiveRecordProxyAdapters::CacheConfiguration
- Includes:
- SynchronizableConfiguration
- Defined in:
- lib/active_record_proxy_adapters/cache_configuration.rb
Overview
rubocop:disable Style/Documentation
Instance Attribute Summary collapse
-
#key_builder ⇒ Proc
A proc that takes an SQL statement and returns a cache key.
-
#key_prefix ⇒ String
The prefix to use for cache keys.
-
#store ⇒ ActiveSupport::Cache::Store
Sets the cache store to use for caching SQL statements.
Instance Method Summary collapse
- #bust ⇒ Object
-
#initialize(lock = Monitor.new) ⇒ CacheConfiguration
constructor
A new instance of CacheConfiguration.
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_builder ⇒ Proc
Returns 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_prefix ⇒ String
Returns 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 |
#store ⇒ ActiveSupport::Cache::Store
Sets the cache store to use for caching SQL statements.
Defaults to {ActiveSupport::Cache::NullStore}, which does not cache anything.
13 14 15 |
# File 'lib/active_record_proxy_adapters/cache_configuration.rb', line 13 def store @store end |
Instance Method Details
#bust ⇒ Object
47 48 49 |
# File 'lib/active_record_proxy_adapters/cache_configuration.rb', line 47 def bust store.delete_matched("#{key_prefix}*") end |