---
title: "Cache Invalidation Complexity: Rails 5.2 and Dalli Cache Store"
description: "Rails 5.2+ applications can fail to invalidate ActiveRecord-backed cache entries when cache versioning is enabled alongside a third-party store such as dalli_store 2.7.8 or earlier. Rails’ recyclable cache keys keep the cache_key stable and store an ActiveRecord cache_version in the entry, preventing unrelated entries from being evicted, but Dalli only understands the key and therefore repeatedly returns stale data. The post explains how to check the production cache_store and active_record.cache_versioning settings, then compares switching to Rails’ :mem_cache_store, disabling versioning, and upgrading Dalli to 2.7.9+. Its recommendation is to use :mem_cache_store and flush the cache, while noting that Dalli 2.7.9 fixes invalidation by putting the version into the key rather than implementing recyclable keys."
---

# Cache Invalidation Complexity: Rails 5.2 and Dalli Cache Store

[Heroku](https://yomu.fyi/company/heroku) · Richard Schneeman · Oct 16, 2018

**Type:** Problem & solution

## Summary

Rails 5.2+ applications can fail to invalidate ActiveRecord-backed cache entries when cache versioning is enabled alongside a third-party store such as dalli\_store 2.7.8 or earlier. Rails’ recyclable cache keys keep the cache\_key stable and store an ActiveRecord cache\_version in the entry, preventing unrelated entries from being evicted, but Dalli only understands the key and therefore repeatedly returns stale data. The post explains how to check the production cache\_store and active\_record.cache\_versioning settings, then compares switching to Rails’ :mem\_cache\_store, disabling versioning, and upgrading Dalli to 2.7.9+. Its recommendation is to use :mem\_cache\_store and flush the cache, while noting that Dalli 2.7.9 fixes invalidation by putting the version into the key rather than implementing recyclable keys.

## Context

Rails 5.2 introduced recyclable cache keys through ActiveRecord cache versioning, but third-party cache stores must understand the new cache-entry versioning behavior. With dalli\_store 2.7.8 or earlier and cache versioning enabled, the stable cache\_key prevents changed ActiveRecord objects from invalidating cached values.

## Approach / What changed

The post provides production configuration checks and evaluates three mitigations: switching to Rails’ :mem\_cache\_store, disabling config.active\_record.cache\_versioning, or upgrading Dalli to 2.7.9+. It recommends :mem\_cache\_store followed by a cache flush, and proposes a capability check for custom stores.

## Takeaways

- Rails’ :mem\_cache\_store supports cache key recycling and compression; preliminary CodeTriage benchmarks found performance within 1% of the prior raw dalli\_store setup.
- Disabling cache versioning avoids the incompatibility but changes the cache-key format, effectively producing a cold cache and forfeiting recyclable keys and cache compression.
- Dalli 2.7.9 fixes the invalidation problem by inserting the version into the cache key, but it does not implement Rails’ recyclable cache-key behavior.

**Tags:** [Caching](https://yomu.fyi/topic/caching), [Dalli](https://yomu.fyi/topic/dalli), [Ruby on Rails](https://yomu.fyi/topic/ruby-on-rails)

- Source: [Heroku](https://www.heroku.com/blog/cache-invalidation-rails-5-2-dalli-store)
- Source URL: https://www.heroku.com/blog/cache-invalidation-rails-5-2-dalli-store
- Ingested by Yomu: 2026-09-09T14:26:51.192Z

[Read original post](https://www.heroku.com/blog/cache-invalidation-rails-5-2-dalli-store)
