Skip to content

Implemented #cache_version conventional method#29107

Closed
bogdan wants to merge 1 commit intorails:versioned-cache-entriesfrom
bogdan:cache-model-versioning
Closed

Implemented #cache_version conventional method#29107
bogdan wants to merge 1 commit intorails:versioned-cache-entriesfrom
bogdan:cache-model-versioning

Conversation

@bogdan
Copy link
Contributor

@bogdan bogdan commented May 16, 2017

Implemented #cache_version conventional method for the default cache version option value.

Examples:

Rails.cache.fetch(["post_preview", post])
Rails.cache.fetch(["post_preview", post, post.author]) 

class Post
  def cache_key
     "posts/#{id}"
  end
  def cache_version
    updated_at
  end
end

@rails-bot
Copy link

r? @schneems

(@rails-bot has picked a reviewer for you, use r? to override)

@rails-bot
Copy link

warning Warning warning

  • Pull requests are usually filed against the master branch for this repo, but this one is against versioned-cache-entries. Please double check that you specified the right target!

@bogdan
Copy link
Contributor Author

bogdan commented May 16, 2017

r? @dhh

@rails-bot rails-bot assigned dhh and unassigned schneems May 16, 2017
@bogdan bogdan mentioned this pull request May 16, 2017
@dhh
Copy link
Member

dhh commented May 16, 2017

To flesh this out, you'll need to consider backwards compatibility with the keys generated by the cache and what to do about the fact that cache_key currently includes the updated_at version for ARs.

@dhh
Copy link
Member

dhh commented May 16, 2017

If we make the presence of the #cache_version method the trigger for #cache_key only returning the stable key, then we avoid the backwards incompatibility problem. Want to take a stab at that?

The method can be defined besides #cache_key for all models
passed to ActiveSupport::Cache::Store to be used as a default
cache version.
@bogdan bogdan force-pushed the cache-model-versioning branch from 117ceb6 to 105e1cb Compare May 16, 2017 12:21
@kaspth
Copy link
Contributor

kaspth commented May 20, 2017

@bogdan you still want to pursue this version further or is the merged version better now? 😊

@bogdan
Copy link
Contributor Author

bogdan commented May 20, 2017

Merged has all the ideas from here.

@bogdan bogdan closed this May 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants