Sha256: 8bff594f946aa1abe86a0326552bf21b42ab0f9f2d7a3863e55a57528b6924cf
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
require 'fileutils' require 'glue/configuration' require 'glue/attribute' require 'glue/cache/memory' module Nitro # Adds support for caching. module Caching # Action caching. Caches a fragment, ie a page part. # Use output caching for full page caching. module Fragments # The cache used to store the fragments. setting :cache, :default => Glue::MemoryCache.new, :doc => 'The cache used to store the fragments' def self.get(name, options = {}) return @@cache.get(name, options) end def self.put(name, content = nil, options = {}) @@cache.put(name, content, options) return content end private # Helper method to cache a fragment. # # === Example # # ... # <h1>Article list</h1> # # <?r cache(:my_cache_key) do ?> # <ul> # <li each="a in Article.all">#{a.title}</li> # </ul> # <?r end ?> # ... def cache(name = nil, options = {}, &block) name = @action_name unless name cache_fragment(block, "#{name}#{options}", options) end # Internal method, prefer to use cache instead. def cache_fragment(block, name, options = {}) unless caching_enabled? block.call return end if fragment = Fragments.get(name, options) @out << fragment else pos = @out.length block.call Fragments.put(name, @out[pos..-1], options) end end # Expire a cached fragment. #-- # gmosx: If you modify the code here, don't forget to modify # the same method on the sweeper. #++ def expire_fragment(name, options = {}) Fragments.cache.delete(name, options) end end end end # * George Moschovitis <gm@navel.gr>
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.30.0 | lib/nitro/caching/fragments.rb |