Skip to content

Instantly share code, notes, and snippets.

@taktamur
Created November 11, 2012 11:25
Show Gist options
  • Save taktamur/4054628 to your computer and use it in GitHub Desktop.
Save taktamur/4054628 to your computer and use it in GitHub Desktop.
Railsでオブジェクトのキャッシュ
# Railsでcache (Rails.cache.fetch)
# http://blog.twiwt.org/e/ff4c23
# キャッシュの種類は、デフォルトはファイルキャッシュ
# ファイルキャッシュの場所はtmp/cache/以下
# 切り替えるには、config/environments/production.rb 等で"config.cache_store"を書き換える
gistID = j['id']
@contents[gistID] = Rails.cache.fetch( gistID, :expires_in => 1.hour) do
rawURL = j['files'][ j['files'].keys[0] ]['raw_url']
{ "raw" => URI.parse(rawURL).read };
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment