IdentityCache: Improving Performance one Cached Model at a Time - Shopify
Apr 4, 2013

Summary
Introduced IdentityCache, an open-sourced library for caching ActiveRecord models in Memcached. IdentityCache acts as a read-through cache, fetching from Memcached first and then the database on a miss, storing the result in Memcached. It automatically handles cache expiration via `after_commit` hooks and supports caching single objects, associations (`cache_has_many`, `cache_has_one`, `cache_belongs_to`), and embedding associations within parent objects. The library allows for defining custom indexes for accessing models and aims to reduce database read operations significantly, as demonstrated by performance improvements during flash sales.
More from the Data Store Selection and Usage trail
- We replaced Redis with MySQL for inventory reservations—and it scaled (2026) - Shopify
- Mitigating Deadlocks in high concurrency environments - Shopify
- Safely Adding NOT NULL Columns to Your Database Tables - Shopify
- Double Entry Transition Tables: How We Track State Changes At Shopify - Shopify
- Shopify’s Unique Data Science Hierarchy Of Needs - Shopify