module Sequel::IndexCaching

Public Class Methods

extended(db) click to toggle source

Set index cache to the empty hash.

# File lib/sequel/extensions/index_caching.rb, line 52
def self.extended(db)
  db.instance_variable_set(:@indexes, {})
end

Public Instance Methods

dump_index_cache(file) click to toggle source

Dump the index cache to the filename given in Marshal format.

# File lib/sequel/extensions/index_caching.rb, line 57
def dump_index_cache(file)
  indexes = {}
  @indexes.sort.each do |k, v|
    indexes[k] = v
  end
  File.open(file, 'wb'){|f| f.write(Marshal.dump(indexes))}
  nil
end
dump_index_cache?(file) click to toggle source

Dump the index cache to the filename given unless the file already exists.

# File lib/sequel/extensions/index_caching.rb, line 68
def dump_index_cache?(file)
  dump_index_cache(file) unless File.exist?(file)
end
indexes(table, opts=OPTS) click to toggle source

If no options are provided and there is cached index information for the table, return the cached information instead of querying the database.

Calls superclass method
# File lib/sequel/extensions/index_caching.rb, line 88
def indexes(table, opts=OPTS)
  return super unless opts.empty?

  quoted_name = literal(table)
  if v = Sequel.synchronize{@indexes[quoted_name]}
    return v
  end

  result = super
  Sequel.synchronize{@indexes[quoted_name] = result}
  result
end
load_index_cache(file) click to toggle source

Replace the index cache with the data from the given file, which should be in Marshal format.

# File lib/sequel/extensions/index_caching.rb, line 74
def load_index_cache(file)
  @indexes = Marshal.load(File.read(file))
  nil
end
load_index_cache?(file) click to toggle source

Replace the index cache with the data from the given file if the file exists.

# File lib/sequel/extensions/index_caching.rb, line 81
def load_index_cache?(file)
  load_index_cache(file) if File.exist?(file)
end

Private Instance Methods

remove_cached_schema(table) click to toggle source

Remove the index cache for the given schema name

Calls superclass method
# File lib/sequel/extensions/index_caching.rb, line 104
def remove_cached_schema(table)
  k = quote_schema_table(table)
  Sequel.synchronize{@indexes.delete(k)}
  super
end