Skip to content

Instantly share code, notes, and snippets.

@nateleavitt
Created January 21, 2011 09:43
Show Gist options
  • Save nateleavitt/789475 to your computer and use it in GitHub Desktop.
Save nateleavitt/789475 to your computer and use it in GitHub Desktop.
cache code
User
def current_user
@current_user ||= Rails.cache.fetch("customerhub:current:user:#{session[:user_id]}:v#{HUB_VERSION}",
:expires_in => 20.minutes) {
User.find(session[:user_id])
}
end
# Will either fetch the current account or return nil if none is found
Account
def current_account
@current_account ||= Rails.cache.fetch("customerhub:current:account:#{current_subdomain}:v#{HUB_VERSION}"){
Account.find_by_subdomain(current_subdomain)
}
end
Style
def current_style
@current_style ||= Rails.cache.fetch("customerhub:current:style:#{current_subdomain}:v#{HUB_VERSION}") {
Style.find_by_account_id(current_account.id, :select => "id, account_id, header, header_background, page, page_hover, h1, top_link_hover, table_header, company_logo_file_name, company_logo_content_type, company_logo_file_size, page_styles, sub_link")
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment