Skip to content

Commit

Permalink
Making use of GenericMutedWorker backgroundrb worker to clear an enti…
Browse files Browse the repository at this point in the history
…re locale's cache if a locale has an interface change.
  • Loading branch information
Walter McGinnis committed Jul 22, 2010
1 parent 41f0bf8 commit 592ac0d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
@@ -1,3 +1,32 @@
TranslationsController.class_eval do
uses_tiny_mce :options => Kete.translatable_tiny_mce_options, :only => %w{ new edit }

include WorkerControllerHelpers

after_filter :expire_locale_cache, :only => [:create, :update]

private

# this is the big hammer for translation clearing
# it does the entire locale's cache if a translation changes
# only use on UI element related models
# Kete items (i.e. user generated content) should be done on an item by item basis
def expire_locale_cache
# leave Kete items to be cleared individually
return true if ZOOM_CLASSES.include?(@translatable_class.to_s)

expire_locale = @translation.locale
method_name = "clear_locale_cache"
options = { :locale_to_clear => expire_locale }

worker_type = :generic_muted_worker
worker_key = worker_key_for("generic_muted_worker_#{method_name}_#{expire_locale}")

# only allow a single cache clearing to happen at once
MiddleMan.new_worker( :worker => worker_type,
:worker_key => worker_key )

MiddleMan.worker(worker_type, worker_key).async_do_work( :arg => { :method_name => method_name, :options => options } )
true
end
end
14 changes: 13 additions & 1 deletion rails/init.rb
Expand Up @@ -40,6 +40,18 @@
Kete.extensions[:blocks][key] << Proc.new { Kernel.load(ext_path) }
end

# extend the Generic Muted Worker to have the expire_locale method
MethodsForGenericMutedWorker.module_eval do
def clear_locale_cache(options = { })
locale_to_clear = options[:locale_to_clear]
raise unless locale_to_clear

# WARNING: this relies on the fact that Kete's current caching scheme is file system based
# if an option for Memcache or other caching mechanism is used in the future
# this will need to be updated with logic to figure out correct clearing mechanism
file_path = "#{Rails.root}/tmp/cache/views/#{Kete.site_name}/#{locale_to_clear}"
FileUtils.rm_r(file_path, :force => true) if File.exist?(file_path) && File.directory?(file_path)
end
end
end

end

0 comments on commit 592ac0d

Please sign in to comment.