public
Last active

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 
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
gistfile2.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.