Skip to content

@grosser /gist:170853
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
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
Something went wrong with that request. Please try again.