Module: Tennpipes::Cache
- Defined in:
- lib/tennpipes-memory.rb,
lib/tennpipes-memory/helpers/page.rb,
lib/tennpipes-memory/helpers/fragment.rb,
lib/tennpipes-memory/helpers/cache_store.rb,
lib/tennpipes-memory/helpers/cache_object.rb
Overview
This component enables caching of an application’s response contents on both page- and fragment-levels. Output cached in this manner is persisted, until it expires or is actively expired, in a configurable store of your choosing. Several common caching stores are supported out of the box.
Defined Under Namespace
Modules: Helpers
Class Method Summary collapse
- .included(base) ⇒ Object
- .new(name, options = {}) ⇒ Object
-
.registered(app) ⇒ Object
Register these helpers:.
- .tennpipes_route_added(route, verb, path, args, options, block) ⇒ Object
Class Method Details
.included(base) ⇒ Object
108 109 110 |
# File 'lib/tennpipes-memory.rb', line 108 def included(base) base.extend Tennpipes::Cache::Helpers::Page::ClassMethods end |
.new(name, options = {}) ⇒ Object
117 118 119 120 121 |
# File 'lib/tennpipes-memory.rb', line 117 def self.new(name, = {}) # Activate expiration by default [:expires] = true unless .include?(:expires) Moneta.new(name, ) end |
.registered(app) ⇒ Object
Register these helpers:
Tennpipes::Cache::Helpers::ObjectCache
Tennpipes::Cache::Helpers::CacheStore
Tennpipes::Cache::Helpers::Fragment
Tennpipes::Cache::Helpers::Page
for Tennpipes::Application.
By default we use FileStore as showed below:
set :cache, Tennpipes::Cache.new(:File, :dir => Tennpipes.root('tmp', app_name.to_s, 'cache'))
However, you can also change the file store easily in your app.rb:
set :cache, Tennpipes::Cache.new(:LRUHash) # Keeps cached values in memory
set :cache, Tennpipes::Cache.new(:Memcached) # Uses default server at localhost
set :cache, Tennpipes::Cache.new(:Memcached, '127.0.0.1:11211', :exception_retry_limit => 1)
set :cache, Tennpipes::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
set :cache, Tennpipes::Cache.new(:Redis) # Uses default server at localhost
set :cache, Tennpipes::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
set :cache, Tennpipes::Cache.new(:Redis, :backend => redis_instance)
set :cache, Tennpipes::Cache.new(:Mongo) # Uses default server at localhost
set :cache, Tennpipes::Cache.new(:Mongo, :backend => mongo_client_instance)
set :cache, Tennpipes::Cache.new(:File, :dir => Tennpipes.root('tmp', app_name.to_s, 'cache')) # default choice
You can manage your cache from anywhere in your app:
MyApp.cache['val'] = 'test'
MyApp.cache['val'] # => 'test'
MyApp.cache.delete('val')
MyApp.cache.clear
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/tennpipes-memory.rb', line 95 def registered(app) app.helpers Tennpipes::Cache::Helpers::ObjectCache app.helpers Tennpipes::Cache::Helpers::CacheStore app.helpers Tennpipes::Cache::Helpers::Fragment app.helpers Tennpipes::Cache::Helpers::Page unless app.respond_to?(:cache) cache_dir = Tennpipes.root('tmp', defined?(app.app_name) ? app.app_name.to_s : '', 'cache') app.set :cache, Tennpipes::Cache.new(:File, :dir => cache_dir) end app.disable :caching unless app.respond_to?(:caching) included(app) end |
.tennpipes_route_added(route, verb, path, args, options, block) ⇒ Object
112 113 114 |
# File 'lib/tennpipes-memory.rb', line 112 def tennpipes_route_added(route, verb, path, args, , block) Tennpipes::Cache::Helpers::Page.tennpipes_route_added(route, verb, path, args, , block) end |