Skip to content

Instantly share code, notes, and snippets.

@bsa7
Created March 15, 2016 19:32
Show Gist options
  • Save bsa7/5aa3dd19f9eb6887ec56 to your computer and use it in GitHub Desktop.
Save bsa7/5aa3dd19f9eb6887ec56 to your computer and use it in GitHub Desktop.
ruby own blocks
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