Class: ActiveRecord::ConnectionAdapters::QueryCache::Store
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::QueryCache::Store
- Defined in:
- 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(max_size) ⇒ Store
constructor
A new instance of Store.
- #size ⇒ Object
Constructor Details
#initialize(max_size) ⇒ Store
Returns a new instance of Store.
38 39 40 41 42 43 |
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 38 def initialize(max_size) @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.
34 35 36 |
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 34 def dirties @dirties end |
#enabled ⇒ Object Also known as: enabled?
Returns the value of attribute enabled.
34 35 36 |
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 34 def enabled @enabled end |
Instance Method Details
#[](key) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 53 def [](key) return unless @enabled if entry = @map.delete(key) @map[key] = entry end end |
#clear ⇒ Object
75 76 77 78 |
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 75 def clear @map.clear self end |
#compute_if_absent(key) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 61 def compute_if_absent(key) 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
49 50 51 |
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 49 def empty? @map.empty? end |
#size ⇒ Object
45 46 47 |
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 45 def size @map.size end |