rubyactivesupport

Set ActiveSupport cache_format_version when not using rails


I have a small application that uses ActiveSupport::Cache (via require 'active_support/cache'), and is not a full rails application. How do I set the cache.active_support_cache_format_version to solve for the pending deprecation?

https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#new-activesupport-cache-serialization-format

I use it with:

@cache = ActiveSupport::Cache::FileStore.new("/tmp/[...]"))
@cache.fetch([...]) do
 
end

I don't have any other ActiveSupport modules in my application.

Everything I can find is referencing setting this in Rails config, which doesn't exist in my application. I expected I could set it on the cache object directly, but it doesn't appear to have any available methods to accomplish this.

I checked https://api.rubyonrails.org/classes/ActiveSupport/Cache.html as well as .methods, and even .private_methods in case there was something not public I could explore.


Solution

  • It's just an attribute accessor:

    ActiveSupport::Cache.format_version = 7.0
    
    1. https://github.com/rails/rails/blob/v7.1.3.2/railties/lib/rails/application/bootstrap.rb#L77

    2. https://github.com/rails/rails/blob/v7.1.3.2/activesupport/lib/active_support.rb#L109

    3. https://github.com/rails/rails/blob/v7.1.3.2/activesupport/lib/active_support/cache.rb#L58