123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::ConnectionAdapters::QueryCache::Store

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(version, max_size) ⇒ Store

[ GitHub ]

  
# 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? (rw)

Alias for #dirties.

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 37

alias_method :dirties?, :dirties

#empty?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 53

def empty?
  check_version
  @map.empty?
end

#enabled? (rw)

Alias for #enabled.

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 36

alias_method :enabled?, :enabled

Instance Method Details

#[](key)

[ GitHub ]

  
# 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

#check_version (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 89

def check_version
  if @current_version != @version.value
    @map.clear
    @current_version = @version.value
  end
end

#clear

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 83

def clear
  @map.clear
  self
end

#compute_if_absent(key)

[ GitHub ]

  
# 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

#dirties (rw) Also known as: #dirties?

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 35

attr_accessor :enabled, :dirties

#enabled (rw) Also known as: #enabled?

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 35

attr_accessor :enabled, :dirties

#size

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 48

def size
  check_version
  @map.size
end