Last active
January 4, 2016 09:09
-
-
Save bogn/8600648 to your computer and use it in GitHub Desktop.
Naming is hard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ItemCaching | |
| extend ActiveSupport::Concern | |
| def self.cache_all_items_grouped_by_group | |
| Rails.cache.fetch(:items_grouped_by_group) do | |
| Item.all.group_by {|i| i.group_id } | |
| end | |
| end | |
| def self.belonging_to_group_from_cache(group_id) | |
| Rails.cache.read(:items_grouped_by_group)[group_id] || [] | |
| end | |
| end |
Author
Author
Item.cached_for_group(group.id) is a good suggestion.
Author
cached_for_group it is.
Author
Made the model concern more general.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
COMMENT IS FOR 1b897ab384
This is a concern that gets mixed into Item. So a call would be
Completely unsatisfied with the method names. The mentioned method returns multiple items but doesn't indicate that by its name for example.