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