Class: ArCache::Table
Constant Summary collapse
- OPTIONS =
%i[disabled select_disabled unique_indexes].freeze
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#cache_key_prefix ⇒ Object
readonly
Returns the value of attribute cache_key_prefix.
-
#column_indexes ⇒ Object
readonly
Returns the value of attribute column_indexes.
-
#column_names ⇒ Object
readonly
Returns the value of attribute column_names.
-
#md5 ⇒ Object
readonly
Returns the value of attribute md5.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#primary_key ⇒ Object
readonly
Returns the value of attribute primary_key.
-
#unique_indexes ⇒ Object
readonly
Returns the value of attribute unique_indexes.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key(where_values_hash, index, multi_values_key = nil, key_value = nil) ⇒ Object
- #disabled? ⇒ Boolean
-
#initialize(table_name) ⇒ Table
constructor
A new instance of Table.
- #primary_cache_key(id) ⇒ Object
- #select_disabled? ⇒ Boolean
- #update_version ⇒ Object
- #version ⇒ Object
Methods included from Marshal
Constructor Details
#initialize(table_name) ⇒ Table
Returns a new instance of Table.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ar_cache/table.rb', line 25 def initialize(table_name) @name = table_name @cache_key_prefix = "arcache:#{@name}:version" @primary_key = connection.primary_key(@name) columns = connection.columns(@name) = ArCache::Configuration.(@name) @unique_indexes = normalize_unique_indexes(.delete(:unique_indexes), columns).freeze .each { |k, v| instance_variable_set("@#{k}", v) } @disabled = true if @primary_key.nil? # ArCache is depend on primary key implementation. @column_names = columns.map(&:name).freeze @column_indexes = @unique_indexes.flatten.uniq.freeze coder = ArCache::Configuration.coder @md5 = Digest::MD5.hexdigest("#{coder}-#{@disabled}-#{columns.to_json}") ArCache::Record.store(self) self.class.all << self end |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
9 10 11 |
# File 'lib/ar_cache/table.rb', line 9 def all @all end |
#cache_key_prefix ⇒ Object (readonly)
Returns the value of attribute cache_key_prefix.
11 12 13 |
# File 'lib/ar_cache/table.rb', line 11 def cache_key_prefix @cache_key_prefix end |
#column_indexes ⇒ Object (readonly)
Returns the value of attribute column_indexes.
11 12 13 |
# File 'lib/ar_cache/table.rb', line 11 def column_indexes @column_indexes end |
#column_names ⇒ Object (readonly)
Returns the value of attribute column_names.
11 12 13 |
# File 'lib/ar_cache/table.rb', line 11 def column_names @column_names end |
#md5 ⇒ Object (readonly)
Returns the value of attribute md5.
11 12 13 |
# File 'lib/ar_cache/table.rb', line 11 def md5 @md5 end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/ar_cache/table.rb', line 11 def name @name end |
#primary_key ⇒ Object (readonly)
Returns the value of attribute primary_key.
11 12 13 |
# File 'lib/ar_cache/table.rb', line 11 def primary_key @primary_key end |
#unique_indexes ⇒ Object (readonly)
Returns the value of attribute unique_indexes.
11 12 13 |
# File 'lib/ar_cache/table.rb', line 11 def unique_indexes @unique_indexes end |
Class Method Details
.new(table_name) ⇒ Object
19 20 21 22 23 |
# File 'lib/ar_cache/table.rb', line 19 def self.new(table_name) @lock.synchronize do @all.find { |table| table.name == table_name } || super end end |
Instance Method Details
#cache_key(where_values_hash, index, multi_values_key = nil, key_value = nil) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/ar_cache/table.rb', line 74 def cache_key(where_values_hash, index, multi_values_key = nil, key_value = nil) where_value = index.map do |column| value = column == multi_values_key ? key_value : where_values_hash[column] "#{column}=#{value}" end.sort.join('&') "#{cache_key_prefix}:#{version}:#{where_value}" end |
#disabled? ⇒ Boolean
44 45 46 |
# File 'lib/ar_cache/table.rb', line 44 def disabled? @disabled end |
#primary_cache_key(id) ⇒ Object
70 71 72 |
# File 'lib/ar_cache/table.rb', line 70 def primary_cache_key(id) "#{cache_key_prefix}:#{version}:#{primary_key}=#{id}" end |
#select_disabled? ⇒ Boolean
48 49 50 |
# File 'lib/ar_cache/table.rb', line 48 def select_disabled? @select_disabled end |