Skip to content

Instantly share code, notes, and snippets.

@ritikesh
Last active May 21, 2020 15:29
Show Gist options
  • Save ritikesh/aae1cc94912501f63bfb7a67517ce2a2 to your computer and use it in GitHub Desktop.
Save ritikesh/aae1cc94912501f63bfb7a67517ce2a2 to your computer and use it in GitHub Desktop.
blog gists
module Memcache
KEY_HASH = YAML.load_file(File.join(Rails.root, 'config', 'memcached_keys.yml')).symbolize_keys!
def self.key(key, value)
“#{KEY_HASH[key]}:#{value}”
end
def self.multi_key(key, value1, value2)
“#{KEY_HASH[key]}:#{value1}:#{value2}”
end
end
Memcache::TENANT_BY_ID = "TENANT_BY_ID:%{tenant_id}"
Benchmark.bmbm { |x|
x.report(‘existing’) {
1000.times do |n|
1000.times {
Memcache::TENANT_BY_ID % { tenant_id: n }
}
end
}
x.report(‘new’) {
1000.times do |n|
1000.times {
Memcache.key(:tenant_by_id, n)
}
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment