A blob-level read-through caching solution for ActiveRecord that adds fetch methods to cache model objects and associations using Memcached.
IdentityCache is a blob-level caching solution that plugs into ActiveRecord to provide read-through caching for model objects and their associations. It reduces database queries by storing serialized records in Memcached and automatically fetching them via added methods like `fetch` and `fetch_by_*`. The library is production-tested and extracted from Shopify, focusing on scaling read operations in Rails applications.
Rails developers working on high-traffic, read-heavy applications who need to reduce database load and improve response times through efficient caching of ActiveRecord models.
Developers choose IdentityCache for its seamless integration with ActiveRecord, flexible indexing options, and association embedding, which simplify caching strategies without altering existing Rails associations. Its opt-in design ensures cache inconsistency risks are controlled, and it includes robust cache invalidation mechanisms.
IdentityCache is a blob level caching solution to plug into Active Record. Don't #find, #fetch!
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Adds convenience methods like fetch and fetch_by_* directly to models, allowing easy adoption without altering existing Rails associations, as shown in basic usage examples.
Supports secondary indexes and composite keys for efficient lookups beyond primary IDs, enabling cache_index usage on fields like handle or vendor and product_type.
Allows embedding has_many or has_one associations with embed: true, loading related data in a single cache fetch to reduce database queries, as demonstrated with Product and images.
Provides fetch_multi and fetch_multi_by_* methods for efficient retrieval of multiple records, optimizing cache usage for bulk read operations from the README examples.
Enables caching of individual attributes via cache_attribute with custom keys, minimizing cache payload size for specific use cases like fetching target by shop_id and path.
The library explicitly warns that cache invalidations can be lost due to network failures or Memcached issues, making it unsuitable for data-critical applications where staleness is unacceptable.
Requires detailed configuration with Memcached backends, initializer setup, and choice between clients like Dalli or memcached_store, which can be error-prone compared to simpler caching solutions.
Designed specifically for Memcached as the backend cache store, limiting flexibility for teams using alternative systems like Redis without significant modifications.
Relies on ActiveRecord after_commit hooks for cache expiration, which might not cover all database write scenarios, leading to potential stale cache entries if hooks are missed.