module Sequel::Plugins::StaticCacheCache::ClassMethods

def _load_static_cache_rows(ds, key)

and update the cache with them.
query if present. Otherwise, get all records in the provided dataset,
Check the cache first for the key, and return rows without a database
def _load_static_cache_rows(ds, key)
  if rows = Sequel.synchronize{@static_cache_cache[key]}
    rows.map{|row| call(row)}.freeze
  else
    rows = ds.all.freeze
    raw_rows = rows.map(&:values)
    Sequel.synchronize{@static_cache_cache[key] = raw_rows}
    rows
  end
end

def dump_static_cache_cache

Dump the in-memory cached rows to the cache file.
def dump_static_cache_cache
  File.open(@static_cache_cache_file, 'wb'){|f| f.write(Marshal.dump(sort_static_cache_hash(@static_cache_cache)))}
  nil
end

def load_static_cache_rows

then update the cache with the raw rows.
If not available, load the rows from the database, and
Load the rows for the model from the cache if available.
def load_static_cache_rows
  _load_static_cache_rows(dataset, name)
end

def load_subset_static_cache_rows(ds, meth)

then update the cache with the raw rows.
If not available, load the rows from the database, and
Load the rows for the subset from the cache if available.
def load_subset_static_cache_rows(ds, meth)
  _load_static_cache_rows(ds, [name, meth].freeze)
end

def sort_static_cache_hash(cache)

the same static cache values will result in the same marshal file.
Sort the given static cache hash in a deterministic way, so that
def sort_static_cache_hash(cache)
  cache = cache.sort do |a, b|
    a, = a
    b, = b
    if a.is_a?(Array)
      if b.is_a?(Array)
        a_name, a_meth = a
        b_name, b_meth = b
        x = a_name <=> b_name
        if x.zero?
          x = a_meth <=> b_meth
        end
        x
      else
        1
      end
    elsif b.is_a?(Array)
      -1
    else
      a <=> b
    end
  end
  Hash[cache]
end