Revert "PERF: use distributed cache for site text and category slugs"

This reverts commit a97f2eee054bbd5a252e7cc28ea11210b2a8a82d.
This commit is contained in:
Sam
2014-11-12 10:01:07 +11:00
parent 81f391e97f
commit 65e7cd1d1d
5 changed files with 61 additions and 43 deletions

View File

@ -15,16 +15,39 @@ module SiteTextClassMethods
@types << SiteTextType.new(text_type, format, opts)
end
def text_for_cache
@text_for_cache ||= DistributedCache.new("text_for_cache")
end
def text_for(text_type, replacements=nil)
text = nil
text = text_for_cache[text_type] if replacements.blank?
text = cached_text_for(text_type) if replacements.blank?
text ||= uncached_text_for(text_type, replacements)
end
def cached_text_for(text_type)
ensure_subscribed!
@mutex.synchronize do
cache = @text_for_cache[RailsMultisite::ConnectionManagement.current_db]
cache[text_type] if cache
end
end
def store_cached_text_for(text_type, result)
ensure_subscribed!
@mutex.synchronize do
cache = (@text_for_cache[RailsMultisite::ConnectionManagement.current_db] ||= {})
cache[text_type] = result
end
end
def ensure_subscribed!
return if @subscribed
@mutex.synchronize do
MessageBus.subscribe("/text_for") do |message|
@mutex.synchronize do
@text_for_cache[message.site_id] = nil
end
end
end
end
def uncached_text_for(text_type, replacements=nil)
store_cache = replacements.blank?
@ -48,7 +71,7 @@ module SiteTextClassMethods
if store_cache
result.freeze
text_for_cache[text_type] = result
store_cached_text_for(text_type, result)
end
result