Module: Sequel::IndexCaching
- Defined in:
- lib/sequel/extensions/index_caching.rb
Class Method Summary collapse
-
.extended(db) ⇒ Object
Set index cache to the empty hash.
Instance Method Summary collapse
-
#dump_index_cache(file) ⇒ Object
Dump the index cache to the filename given in Marshal format.
-
#dump_index_cache?(file) ⇒ Boolean
Dump the index cache to the filename given unless the file already exists.
-
#indexes(table, opts = OPTS) ⇒ Object
If no options are provided and there is cached index information for the table, return the cached information instead of querying the database.
-
#load_index_cache(file) ⇒ Object
Replace the index cache with the data from the given file, which should be in Marshal format.
-
#load_index_cache?(file) ⇒ Boolean
Replace the index cache with the data from the given file if the file exists.
Class Method Details
.extended(db) ⇒ Object
Set index cache to the empty hash.
53 54 55 |
# File 'lib/sequel/extensions/index_caching.rb', line 53 def self.extended(db) db.instance_variable_set(:@indexes, {}) end |
Instance Method Details
#dump_index_cache(file) ⇒ Object
Dump the index cache to the filename given in Marshal format.
58 59 60 61 62 63 64 65 |
# File 'lib/sequel/extensions/index_caching.rb', line 58 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) ⇒ Boolean
Dump the index cache to the filename given unless the file already exists.
69 70 71 |
# File 'lib/sequel/extensions/index_caching.rb', line 69 def dump_index_cache?(file) dump_index_cache(file) unless File.exist?(file) end |
#indexes(table, opts = OPTS) ⇒ Object
If no options are provided and there is cached index information for the table, return the cached information instead of querying the database.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sequel/extensions/index_caching.rb', line 89 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) ⇒ Object
Replace the index cache with the data from the given file, which should be in Marshal format.
75 76 77 78 |
# File 'lib/sequel/extensions/index_caching.rb', line 75 def load_index_cache(file) @indexes = Marshal.load(File.read(file)) nil end |
#load_index_cache?(file) ⇒ Boolean
Replace the index cache with the data from the given file if the file exists.
82 83 84 |
# File 'lib/sequel/extensions/index_caching.rb', line 82 def load_index_cache?(file) load_index_cache(file) if File.exist?(file) end |