Created
August 20, 2009 05:21
-
-
Save grosser/170853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.after_initialize do | |
#CACHE | |
MEMCACHE_SERVER = case RAILS_ENV | |
when 'development' then 'localhost:11211' | |
when 'staging' then '127.0.0.1:11211' | |
when 'production' then '192.168.2.26:11211' | |
when 'test' then nil | |
else raise | |
end | |
cache = if MEMCACHE_SERVER | |
ActiveSupport::Cache::MemCacheStore.new(MEMCACHE_SERVER, :c_threshold => 10_000,:compression => true,:debug => false,:namespace => 'xxx',:readonly => false,:urlencode => false) | |
else | |
ActiveSupport::Cache::MemoryStore.new | |
end | |
ActionController::Base.cache_store = cache #config.cache_store does not apply to view/controller caching | |
raw_cache = cache.instance_variable_get '@data' | |
CACHE = if cache.is_a? ActiveSupport::Cache::MemoryStore | |
TestCache.new(raw_cache) | |
else | |
raw_cache | |
end | |
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS['cache'] = CACHE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestCache | |
delegate "[]", "[]=", :keys, :delete, :clear, :to=>:@items | |
def initialize(hash) | |
@items = hash | |
end | |
def set(key, object, ttl = nil) | |
@items[key] = object | |
end | |
def get(key) | |
@items[key] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment