Skip to content

Instantly share code, notes, and snippets.

@bluej100
Created July 31, 2015 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluej100/b889aa4234d46519dc66 to your computer and use it in GitHub Desktop.
Save bluej100/b889aa4234d46519dc66 to your computer and use it in GitHub Desktop.
def reload
super
@dependent_cache = {}
end
def dependent_cache(property, key)
@dependent_cache ||= {}
cached = @dependent_cache[property]
return cached[:value] if cached && cached[:key] == key
yield.tap do |value|
@dependent_cache[property] = {
key: key,
value: value,
}
end
end
def direct_reports
dependent_cache(:direct_reports, owned_domain) do
User.by_domain(owned_domain)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment