Module: Sequel::Plugins::StaticCache
- Defined in:
- lib/sequel/plugins/static_cache.rb
Overview
The static_cache plugin is designed for models that are not modified at all in production use cases, or at least where modifications to them would usually coincide with an application restart. When loaded into a model class, it retrieves all rows in the database and staticly caches a ruby array and hash keyed on primary key containing all of the model instances. All of these instances are frozen so they won’t be modified unexpectedly.
The caches this plugin creates are used for the following things:
-
Primary key lookups (e.g. Model)
-
Model.all calls
-
Model.each calls
-
Model.map calls without an argument
-
Model.to_hash calls without an argument
Usage:
# Cache the AlbumType class staticly
AlbumType.plugin :static_cache
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.configure(model) ⇒ Object
Populate the static caches when loading the plugin.
Class Method Details
.configure(model) ⇒ Object
Populate the static caches when loading the plugin.
24 25 26 |
# File 'lib/sequel/plugins/static_cache.rb', line 24 def self.configure(model) model.send(:load_cache) end |