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.
-
#remove_cached_schema(table) ⇒ Object
Remove the index cache for the given schema name.
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.
65 66 67 68 |
# File 'lib/sequel/extensions/index_caching.rb', line 65 def dump_index_cache(file) 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.
72 73 74 |
# File 'lib/sequel/extensions/index_caching.rb', line 72 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.
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/sequel/extensions/index_caching.rb', line 92 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.
78 79 80 81 |
# File 'lib/sequel/extensions/index_caching.rb', line 78 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.
85 86 87 |
# File 'lib/sequel/extensions/index_caching.rb', line 85 def load_index_cache?(file) load_index_cache(file) if File.exist?(file) end |
#remove_cached_schema(table) ⇒ Object
Remove the index cache for the given schema name
58 59 60 61 62 |
# File 'lib/sequel/extensions/index_caching.rb', line 58 def remove_cached_schema(table) k = quote_schema_table(table) Sequel.synchronize{@indexes.delete(k)} super end |