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
53 def self.extended(db)
54   db.instance_variable_set(:@indexes, {})
55 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
58 def dump_index_cache(file)
59   indexes = {}
60   @indexes.sort.each do |k, v|
61     indexes[k] = v
62   end
63   File.open(file, 'wb'){|f| f.write(Marshal.dump(indexes))}
64   nil
65 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
69 def dump_index_cache?(file)
70   dump_index_cache(file) unless File.exist?(file)
71 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
 89 def indexes(table, opts=OPTS)
 90   return super unless opts.empty?
 91 
 92   quoted_name = literal(table)
 93   if v = Sequel.synchronize{@indexes[quoted_name]}
 94     return v
 95   end
 96 
 97   result = super
 98   Sequel.synchronize{@indexes[quoted_name] = result}
 99   result
100 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
75 def load_index_cache(file)
76   @indexes = Marshal.load(File.read(file))
77   nil
78 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
82 def load_index_cache?(file)
83   load_index_cache(file) if File.exist?(file)
84 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
105 def remove_cached_schema(table)
106   k = quote_schema_table(table)
107   Sequel.synchronize{@indexes.delete(k)}
108   super
109 end