Class: ESI::Config
- Inherits:
-
Object
- Object
- ESI::Config
- Defined in:
- lib/esi/config.rb
Overview
This file provides configuration options to mongrel-esi Mongrel ESI is a proxy caching server with limited load balancing capablities
ESI::Config.define(listeners) do|config|
# define the caching rules globally for all routes, defaults to ruby
config.cache do|c|
c.memcached do|mc|
mc.servers = ['localhost:11211'] # memcahed servers
mc.namespace = 'mesi' # namespace for cache storage
end
c.ttl = 600 # default fragment time to live, when <esi:include does not include the max-age attribute
end
# define rules for when to enable esi processing globally for all routes
# using content type it is more flexible, but sometimes you will want to be
# explicit about when to enable esi processing. For those cases, enable_for_surrogate_only will
# require the presense of the Surrogate-Control header to contain the content="ESI/1.0" line.
# see [http://www.w3.org/TR/edge-arch Edge Arch] for details.
config.esi do|c|
c.allowed_content_types = ['text/plain', 'text/html']
#c.enable_for_surrogate_only = true # default is false
end
# define request path routing rules, these rules match against request path to select a specific server
config.routes do|s|
#s.match( /content/ ) do|r|
# r.servers = ['127.0.0.1:4000']
#end
s.default do|r|
r.servers = ['127.0.0.1:3000']
end
end
end
Defined Under Namespace
Classes: CacheConfig, ConfigRouter
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
access configuration values.
-
#cache ⇒ Object
returns the cache object as given in the config/esi.yml cache: key, or defaults to ruby as in uses this process the options allowed are ruby and memcache.
- #enable_esi_processor?(headers) ⇒ Boolean
- #esi {|options| ... } ⇒ Object
-
#initialize(options) ⇒ Config
constructor
A new instance of Config.
- #router ⇒ Object
- #routes {|config_router| ... } ⇒ Object
Constructor Details
#initialize(options) ⇒ Config
Returns a new instance of Config.
46 47 48 |
# File 'lib/esi/config.rb', line 46 def initialize() @config = end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
44 45 46 |
# File 'lib/esi/config.rb', line 44 def config @config end |
Class Method Details
.define(listeners) ⇒ Object
175 176 177 178 179 180 181 182 183 |
# File 'lib/esi/config.rb', line 175 def self.define( listeners ) listeners.each do|host,server| esi_handlers = server.classifier.handler_map.select do|uri,handler| handler.first.class == ESI::Dispatcher end config = esi_handlers.first.last.first.config yield config end end |
Instance Method Details
#[](key) ⇒ Object
access configuration values
51 52 53 |
# File 'lib/esi/config.rb', line 51 def [](key) @config[key] end |
#cache ⇒ Object
returns the cache object as given in the config/esi.yml cache: key, or defaults to ruby as in uses this process the options allowed are ruby and memcache
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/esi/config.rb', line 105 def cache if block_given? # allow this method to be called in config scripts = CacheConfig.new yield if .memcached? @config[:cache] = 'memcached' else @config[:cache] = 'ruby' end @config[:cache_options] = . else cache_type = @config[:cache] = @config[:cache_options] # always return the same cache object, per process $cache ||= case cache_type when 'ruby' ESI::RubyCache.new() when 'memcached' ESI::MemcachedCache.new() else raise "Unsupported cache" end end end |
#enable_esi_processor?(headers) ⇒ Boolean
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/esi/config.rb', line 55 def enable_esi_processor?( headers ) # check for surrogate control configuration # check for matching content type # if both are set it surrogate takes presendence use_esi = false allowed_content_types = @config[:allowed_content_types] if allowed_content_types and headers["content-type"] and allowed_content_types.respond_to?(:detect) use_esi = allowed_content_types.detect do |type| headers["content-type"].match( type ) end use_esi = true if use_esi end if @config[:enable_for_surrogate_only] use_esi = headers["surrogate-control"] and /ESI/.match(headers["surrogate-control"]) end use_esi end |
#esi {|options| ... } ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/esi/config.rb', line 131 def esi = OpenStruct.new({}) yield @config[:allowed_content_types] = .allowed_content_types if .allowed_content_types @config[:enable_for_surrogate_only] = .enable_for_surrogate_only if .enable_for_surrogate_only @config[:chunk_size] = .chunk_size if .chunk_size @config[:max_depth] = .max_depth if .max_depth end |
#router ⇒ Object
140 141 142 |
# File 'lib/esi/config.rb', line 140 def router ESI::Router.new( @config[:routing] ) end |
#routes {|config_router| ... } ⇒ Object
169 170 171 172 173 |
# File 'lib/esi/config.rb', line 169 def routes config_router = ConfigRouter.new yield config_router @config[:routing] = config_router.routes end |