Today Shopify open sourced a core piece of our infrastructure: identity cachegithub.com/Shopify/identi…— Tobias Lütke (@tobi) March 7, 2013
As the quote says, Shopify took a step to open source their solution for caching ActiveRecord model objects in Memcached. An elegant solution backed by a powerful data store, IdentityCache has already been used in production. It’s fairly simple to install, straight from the README:
Add this to your Gemfile:
gem 'identity_cache', :git => 'git://github.com/Shopify/identity_cache.git'
bundle, and tell IdentityCache where Memcached is at:
config.identity_cache_store = :mem_cache_store, Memcached::Rails.new(:servers => ["mem1.server.com"])
Usage is even easier, again from the README!
class Product < ActiveRecord::Base include IdentityCache has_many :images cache_has_many :images, :embed => true end # Fetch the product by it's id, the primary index. @product = Product.fetch(id) # Fetch the images for the Product. # Images are embedded so the product fetch would have # already loaded them. @images = @product.fetch_images
Have comments? Send a tweet to @TheChangelog on Twitter.
Subscribe to The Changelog Weekly – our weekly email covering everything that hits our open source radar.