Module: Sequel::Plugins::StaticCacheCache

Defined in:
lib/sequel/plugins/static_cache_cache.rb

Overview

The static_cache_cache plugin allows for caching the row content for subclasses that use the static cache plugin (or just the current class). Using this plugin can avoid the need to query the database every time loading the plugin into a model, which can save time when you have a lot of models using the static_cache plugin.

Usage:

# Make all model subclasses that use the static_cache plugin use
# the cached values in the given file
Sequel::Model.plugin :static_cache_cache, "static_cache.cache"

# Make the AlbumType model the cached values in the given file,
# should be loaded before the static_cache plugin
AlbumType.plugin :static_cache_cache, "static_cache.cache"

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.configure(model, file) ⇒ Object



21
22
23
24
# File 'lib/sequel/plugins/static_cache_cache.rb', line 21

def self.configure(model, file)
  model.instance_variable_set(:@static_cache_cache_file, file)
  model.instance_variable_set(:@static_cache_cache, File.exist?(file) ? Marshal.load(File.read(file)) : {})
end