Class: Tilt::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/tilt.rb

Overview

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 compiled template object.

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



178
179
180
# File 'lib/sinatra/tilt.rb', line 178

def initialize
  @cache = {}
end

Instance Method Details

#clearObject



186
187
188
# File 'lib/sinatra/tilt.rb', line 186

def clear
  @cache = {}
end

#fetch(*key) ⇒ Object



182
183
184
# File 'lib/sinatra/tilt.rb', line 182

def fetch(*key)
  @cache[key] ||= yield
end