Created
July 31, 2015 20:13
-
-
Save bluej100/b889aa4234d46519dc66 to your computer and use it in GitHub Desktop.
This file contains 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
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