Created
January 18, 2013 09:32
-
-
Save googya/4563428 to your computer and use it in GitHub Desktop.
缓存查出来的结果,避免再次查询
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 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
其他地方如果需要的话,应该确保是最新的内容。使用时候,应清除缓存。。。