Created
February 19, 2014 17:25
-
-
Save arthurnn/9096869 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
require 'active_record' | |
require 'identity_cache' | |
require 'logger' | |
logger = Logger.new nil | |
ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'test', username: 'root') | |
IdentityCache.cache_backend = ActiveSupport::Cache::MemCacheStore.new | |
IdentityCache.logger = logger | |
class Image < ActiveRecord::Base | |
connection.create_table table_name, force: true do |t| | |
t.integer :product_id | |
end | |
include IdentityCache | |
belongs_to :product | |
end | |
class Product < ActiveRecord::Base | |
connection.create_table table_name, force: true do |t| | |
end | |
include IdentityCache | |
has_many :images | |
cache_has_many :images, :embed => true | |
# has_many :pictures, class_name: 'Image' | |
# cache_has_many :pictures, :embed => true | |
end | |
product = Product.create! | |
3.times { Image.create!(product: product) } | |
id = product.id | |
Benchmark.bm do |x| | |
x.report do | |
100_000.times do | |
Product.fetch(id) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
results:
before:
after:
rails 3: