Module: Interlock::Config
- Defined in:
- lib/interlock/config.rb
Constant Summary collapse
- CONFIG_FILE =
"#{RAILS_ROOT}/config/memcached.yml"
Class Method Summary collapse
-
.memcached! ⇒ Object
Configure memcached for this app.
-
.rails! ⇒ Object
Configure Rails to use the memcached store for fragments, and optionally, sessions.
-
.run! ⇒ Object
Load the configuration file, if available, and then set up the Memcached instance, Rails settings, and CACHE constants.
Class Method Details
.memcached! ⇒ Object
Configure memcached for this app.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/interlock/config.rb', line 40 def memcached! Interlock.config[:namespace] << "-#{RAILS_ENV}" unless defined? Object::CACHE klass = MemCacheWithConsistentHashing rescue MemCache Object.const_set('CACHE', klass.new(Interlock.config)) CACHE.servers = Array(Interlock.config[:servers]) end class << CACHE def read(*args) get args.first end def write(name, content, = {}) set(name, content, .is_a?(Hash) ? [:ttl] : Interlock.config[:ttl] ) end end end |
.rails! ⇒ Object
Configure Rails to use the memcached store for fragments, and optionally, sessions.
66 67 68 69 70 71 72 73 74 |
# File 'lib/interlock/config.rb', line 66 def rails! # Memcached fragment caching is mandatory ActionController::Base.fragment_cache_store = CACHE if Interlock.config[:sessions] ActionController::Base.session_store = :mem_cache_store ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update 'cache' => CACHE end end |
.run! ⇒ Object
Load the configuration file, if available, and then set up the Memcached instance, Rails settings, and CACHE constants. Should be more or less compatible with Cache_fu.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/interlock/config.rb', line 24 def run! if File.exist?(CONFIG_FILE) config = YAML.load_file(CONFIG_FILE) config.deep_symbolize_keys! Interlock.config.merge!(config[:defaults] || {}) Interlock.config.merge!(config[RAILS_ENV.to_sym] || {}) end memcached! rails! end |