Skip to content

Instantly share code, notes, and snippets.

@googya
Created January 18, 2013 09:32
Show Gist options
  • Select an option

  • Save googya/4563428 to your computer and use it in GitHub Desktop.

Select an option

Save googya/4563428 to your computer and use it in GitHub Desktop.
缓存查出来的结果,避免再次查询
def get_asset_with_type(type)
unless @_assets
@_assets = self.assets.each_with_object({}) do |asset, result|
result[asset.file_type] = asset
end
end
@_assets[type]
end
def asset_url_of(type)
self.get_asset_with_type(type).try(:data).try(:url)
end
@googya
Copy link
Copy Markdown
Author

googya commented Jan 23, 2013

其他地方如果需要的话,应该确保是最新的内容。使用时候,应清除缓存。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment