-
-
Save svenfuchs/29ec378f9a766b34eb11 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
module I18n | |
module Backend | |
class Caching | |
attr_accessor :backend | |
def translate(*args) | |
result = read_cache(args) and return result | |
write_cache args, backend.translate(*args) | |
end | |
protected | |
def cache | |
@cache ||= {} | |
end | |
def read_cache(key) | |
@cache[key] | |
end | |
def write_cache(key, result) | |
@cache[key] = result | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment