Sha256: ac59059b57ce9604f8dda2e5f4749bc0651fdbf1682212d4d853bd6bcfae9332

Contents?: true

Size: 932 Bytes

Versions: 6

Compression:

Stored size: 932 Bytes

Contents

# Introduces caching of rendered state views into the StatefulWidget.
module Apotomo::Caching
    
  def self.included(base) #:nodoc:
    base.class_eval do
      extend ClassMethods
    end
  end


  module ClassMethods
    # If <tt>version_proc</tt> is omitted, Apotomo provides some basic caching 
    # mechanism: the state view rendered for <tt>state</tt> will be cached as long
    # as you (or e.g. an EventHandler) calls #dirty!. It will then be re-rendered
    # and cached again.
    # You may override that to provide fine-grained caching, with multiple cache versions
    # for the same state.
    def cache(state, version_proc=:cache_version)
      super(state, version_proc)
    end
  end
  
  def cache_version
    @version ||= 0
    {:v => @version}
  end
  
  def increment_version
    @version += 1
  end
  
  # Instruct caching to re-render all cached state views.
  def dirty!
    increment_version
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
apotomo-1.0.0.beta2 lib/apotomo/caching.rb
apotomo-1.0.0.beta1 lib/apotomo/caching.rb
apotomo-0.1.4 lib/apotomo/caching.rb
apotomo-0.1.3 lib/apotomo/caching.rb
apotomo-0.1.2 lib/apotomo/caching.rb
apotomo-0.1.1 lib/apotomo/caching.rb