Rails 7 deprecates the ActiveSupport supplied Time#to_s with a format argument that is used by Mongoid::Cacheable#cache_key to generate a cache key In a Rails 7 project using caching, a deprecation warning will appear in the server logs every time the cache_key method is called.
The solution suggested by the deprecation warning is to switch to ActiveSupport's new Time#to_fs method. However, that method doesn't seem to exist in older versions of ActiveSupport, which would be potentially in use by users of mongoid using older versions of rails. Therefore, I think that using the (unfortunately verbose named) Time#to_formatted_s might be the best option. Older versions of rails have Time#to_formatted_s aliased in ActiveSupport to Time#to_s, whereas Time#to_fs is a new method. The new Time#to_fs method is also aliased to Time#to_formatted_s, so calling it that way should allow it to work without causing deprecation warnings in Rails 7 and earlier versions. It will also prevent any code breaking that could occur when ActiveSupport actually removes their Time#to_s code.