class Tilt::Cache

  1. lib/tilt.rb
Superclass: Object

Extremely simple template cache implementation. Calling applications create a Tilt::Cache instance and use fetch with any set of hashable arguments (such as those to Tilt.new):

cache = Tilt::Cache.new
cache.fetch(path, line, options) { Tilt.new(path, line, options) }

Subsequent invocations return the already loaded template object.

@note

Tilt::Cache is a thin wrapper around Hash.  It has the following
limitations:
* Not thread-safe.
* Size is unbounded.
* Keys are not copied defensively, and should not be modified after
  being passed to #fetch.  More specifically, the values returned by
  key#hash and key#eql? should not change.
If this is too limiting for you, use a different cache implementation.

Methods

Public Class

  1. new

Public Instance

  1. clear
  2. fetch

Public Class methods

new()
[show source]
    # File lib/tilt.rb
120 def initialize
121   @cache = {}
122 end

Public Instance methods

clear()

Clears the cache.

[show source]
    # File lib/tilt.rb
137 def clear
138   @cache = {}
139 end
fetch(*key)

Caches a value for key, or returns the previously cached value. If a value has been previously cached for key then it is returned. Otherwise, block is yielded to and its return value which may be nil, is cached under key and returned. @yield @yieldreturn the value to cache for key

[show source]
    # File lib/tilt.rb
130 def fetch(*key)
131   @cache.fetch(key) do
132     @cache[key] = yield
133   end
134 end