class Sass::CacheStores::Base

@abstract
use the {file:SASS_REFERENCE.md#cache_store-option ‘:cache_store` option}.
To use a cache store with Sass,
{#_store} and {#_retrieve} methods.
it just needs to implement the
Any key-value store can act as such a backend;
An abstract base class for backends for the Sass cache.

def _retrieve(key, version, sha)

Returns:
  • (NilClass) - when the cache key is not found or the version or sha have changed.
  • (String) - The contents that were previously stored.

Parameters:
  • sha (String) -- The sha of the sass source.
  • version (String) -- The current sass version.
  • key (String) -- The key to retrieve
def _retrieve(key, version, sha)
  raise "#{self.class} must implement #_retrieve."
end

def _store(key, version, sha, contents)

Parameters:
  • contents (String) -- The contents to store.
  • sha (String) -- The sha of the sass source.
  • version (String) -- The current sass version.
  • key (String) -- The key to store the contents under
def _store(key, version, sha, contents)
  raise "#{self.class} must implement #_store."
end

def key(sass_dirname, sass_basename)

Parameters:
  • sass_basename (String) -- The name of the Sass file that is being referenced.
  • sass_dirname (String) --
def key(sass_dirname, sass_basename)
  dir = Digest::SHA1.hexdigest(sass_dirname)
  filename = "#{sass_basename}c"
  "#{dir}/#{filename}"
end

def retrieve(key, sha)

Returns:
  • (Object) - The cached object.

Parameters:
  • sha (String) -- The checksum of the root element's content.
  • key (String) -- The key the root element was stored under.
def retrieve(key, sha)
  contents = _retrieve(key, Sass::VERSION, sha)
  Marshal.load(contents) if contents
rescue EOFError, TypeError, ArgumentError, LoadError => e
  Sass::Util.sass_warn "Warning. Error encountered while reading cache #{path_to(key)}: #{e}"
  nil
end

def store(key, sha, root)

Parameters:
  • root (Object) -- The root node to cache.
  • sha (String) -- The checksum for the contents that are being stored.
  • key (String) -- The key to store it under.
def store(key, sha, root)
  _store(key, Sass::VERSION, sha, Marshal.dump(root))
rescue TypeError, LoadError => e
  Sass::Util.sass_warn "Warning. Error encountered while saving cache #{path_to(key)}: #{e}"
  nil
end