Created
March 15, 2016 19:32
-
-
Save bsa7/5aa3dd19f9eb6887ec56 to your computer and use it in GitHub Desktop.
ruby own blocks
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
def cached_entity(key, &block) | |
cache = Rails.cache | |
time_lap = 11.seconds # cache expires each time_lap | |
cache.fetch(key, expires_in: time_lap) do | |
yield | |
end | |
end | |
def cached_nomenclature_ids() | |
cached_entity('nomenclature_ids') do | |
Nomenclature.all.pluck(:id, :parent_id, 'deleted IS NULL') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment