stackshareio/graphql-cache

Support Rails 5.2 recyclable key caching

jeromedalbert opened this issue · 1 comments

With Rails 5.2 and Rails.application.config.active_record.cache_versioning set to true (which is default on config.load_defaults 5.2), some_model.cache_key will always have the same value, e.g. SomeModel/1234. The changing part is #cache_version which by default is the value of updated_at.

This is the concept of recyclable cache keys:

We currently have:

      def guess_id
        return object.cache_key if object.respond_to?(:cache_key)
       ...

This mean that that by default, caching would never expire for models in a new Rails 5.2 app. 🙀I may be wrong as I am trying to wrap my head around how version is exactly handled.

If so, we probably want to change that with either @cache.write(object.cache_key, "bar", version: object.cache_version) / @cache.read(object.cache_key, version: object.cache_version) syntax or maybe just @cache.write(object, "bar") / @cache.read(object) syntax (internally handles whether cache versioning is enabled depending on Rails settings, respond_to :cache_version, etc). Or maybe key.cache_key_with_version if object.respond_to?(:cache_key_with_version) as a first quick fix that won't use cache recycling.

Resolved by #36