Skip to content

Instantly share code, notes, and snippets.

@5minpause
Last active August 29, 2015 14:27
Show Gist options
  • Save 5minpause/a5934e1f740536fdb425 to your computer and use it in GitHub Desktop.
Save 5minpause/a5934e1f740536fdb425 to your computer and use it in GitHub Desktop.
# This is inside Goldencobra::Permission model
after_commit :set_cache_key
def self.restricted?(item)
@@last_permission ||= Goldencobra::Permission.reorder(:updated_at).last
Rails.cache.fetch("#{@@last_permission.cache_key}#{item.cache_key}") do
where(subject_class: item.class, subject_id: item.id).count > 0
end
end
private
def set_cache_key
@@last_permission = Goldencobra::Permission.reorder(:updated_at).last
return true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment