Cache ActiveRecord models in Memcached with IdentityCache by Shopify

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://'

Then bundle, and tell IdentityCache where Memcached is at:

config.identity_cache_store = :mem_cache_store, => [""])

Usage is even easier, again from the README!

class Product < ActiveRecord::Base
  include IdentityCache
  has_many :images
  cache_has_many :images, :embed => true

# 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

IdentityCache also has support for: Secondary Indexes, Caching Associations and more. Head on over to GitHub to View the README or the Source Code.

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

Beyond Code: Season 3 / GopherCon 2015

0:00 / 0:00