Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate cached urls for all frontend locales #1479

Merged
merged 1 commit into from
Mar 20, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions pages/app/models/refinery/page.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -294,16 +294,16 @@ def nested_path
Rails.cache.fetch(path_cache_key) { ['', nested_url].join('/') } Rails.cache.fetch(path_cache_key) { ['', nested_url].join('/') }
end end


def path_cache_key def path_cache_key(locale=::I18n.locale)
[cache_key, 'nested_path'].join('#') [cache_key(locale), 'nested_path'].join('#')
end end


def url_cache_key def url_cache_key(locale=::I18n.locale)
[cache_key, 'nested_url'].join('#') [cache_key(locale), 'nested_url'].join('#')
end end


def cache_key def cache_key(locale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the others have default values of I18n.locale but not this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this method is calling only in path_cache_key and url_cache_key methods and there is locale already set to default value I18n.locale.

[Refinery::Core.base_cache_key, 'page', ::I18n.locale, id].compact.join('/') [Refinery::Core.base_cache_key, 'page', locale, id].compact.join('/')
end end


# Returns true if this page is "published" # Returns true if this page is "published"
Expand Down Expand Up @@ -415,8 +415,10 @@ def invalidate_cached_urls
return true unless Refinery::Pages.marketable_urls return true unless Refinery::Pages.marketable_urls


[self, children].flatten.each do |page| [self, children].flatten.each do |page|
Rails.cache.delete(page.url_cache_key) ::Refinery::I18n.frontend_locales.each do |locale|
Rails.cache.delete(page.path_cache_key) Rails.cache.delete(page.url_cache_key(locale))
Rails.cache.delete(page.path_cache_key(locale))
end
end end
end end
alias_method :invalidate_child_cached_url, :invalidate_cached_urls alias_method :invalidate_child_cached_url, :invalidate_cached_urls
Expand Down