Class: ActiveRecord::ConnectionAdapters::QueryCache::Store
- Defined in:
- activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#dirties ⇒ Object
(also: #dirties?)
Returns the value of attribute dirties.
-
#enabled ⇒ Object
(also: #enabled?)
Returns the value of attribute enabled.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #compute_if_absent(key) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(version, max_size) ⇒ Store
constructor
A new instance of Store.
- #size ⇒ Object
Constructor Details
#initialize(version, max_size) ⇒ Store
Returns a new instance of Store.
39 40 41 42 43 44 45 46 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 39 def initialize(version, max_size) @version = version @current_version = version.value @map = {} @max_size = max_size @enabled = false @dirties = true end |
Instance Attribute Details
#dirties ⇒ Object Also known as: dirties?
Returns the value of attribute dirties.
35 36 37 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 35 def dirties @dirties end |
#enabled ⇒ Object Also known as: enabled?
Returns the value of attribute enabled.
35 36 37 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 35 def enabled @enabled end |
Instance Method Details
#[](key) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 58 def [](key) check_version return unless @enabled if entry = @map.delete(key) @map[key] = entry end end |
#clear ⇒ Object
83 84 85 86 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 83 def clear @map.clear self end |
#compute_if_absent(key) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 67 def compute_if_absent(key) check_version return yield unless @enabled if entry = @map.delete(key) return @map[key] = entry end if @max_size && @map.size >= @max_size @map.shift # evict the oldest entry end @map[key] ||= yield end |
#empty? ⇒ Boolean
53 54 55 56 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 53 def empty? check_version @map.empty? end |
#size ⇒ Object
48 49 50 51 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 48 def size check_version @map.size end |