Skip to content

Instantly share code, notes, and snippets.

@PikachuEXE
Forked from subelsky/check_for_memcached.rb
Last active December 21, 2015 12:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Use memcached as cache store on development if it is running
# Use a different cache store based on memcached is running or not
begin
# check if memcached is running; if it is, use that instead of the default memory cache
Timeout.timeout(0.5) { TCPSocket.open("localhost", 11211) { } }
config.cache_store = :dalli_store, %w(localhost:11211), {namespace: Rails.application.class.parent_name, expires_in: 1.day, compress: true}
$stderr.puts "Using memcached on localhost:11211"
rescue StandardError
$stderr.puts "memcached not running, caching to memory"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment