class Sinatra::Helpers::Stream::TemplateCache

Extremely simple template cache implementation.

* 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.

Implementation copied from Tilt::Cache.

Public Class Methods

new() click to toggle source
    # File lib/sinatra/base.rb
943 def initialize
944   @cache = {}
945 end

Public Instance Methods

clear() click to toggle source

Clears the cache.

    # File lib/sinatra/base.rb
958 def clear
959   @cache = {}
960 end
fetch(*key) { || ... } click to toggle source

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.

    # File lib/sinatra/base.rb
951 def fetch(*key)
952   @cache.fetch(key) do
953     @cache[key] = yield
954   end
955 end