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
65 def dump_index_cache(file)
66   File.open(file, 'wb'){|f| f.write(Marshal.dump(@indexes))}
67   nil
68 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
72 def dump_index_cache?(file)
73   dump_index_cache(file) unless File.exist?(file)
74 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
 92 def indexes(table, opts=OPTS)
 93   return super unless opts.empty?
 94 
 95   quoted_name = literal(table)
 96   if v = Sequel.synchronize{@indexes[quoted_name]}
 97     return v
 98   end
 99 
100   result = super
101   Sequel.synchronize{@indexes[quoted_name] = result}
102   result
103 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
78 def load_index_cache(file)
79   @indexes = Marshal.load(File.read(file))
80   nil
81 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
85 def load_index_cache?(file)
86   load_index_cache(file) if File.exist?(file)
87 end
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
58 def remove_cached_schema(table)
59   k = quote_schema_table(table)
60   Sequel.synchronize{@indexes.delete(k)}
61   super
62 end