app/models/tr8n/translation_source.rb in tr8n-3.1.8 vs app/models/tr8n/translation_source.rb in tr8n-3.2.0
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2010-2011 Michael Berkovich, tr8n.net
+# Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@@ -33,20 +33,28 @@
alias :domain :translation_domain
alias :sources :translation_key_sources
alias :keys :translation_keys
+ def self.cache_key(source)
+ "translation_source_#{source}"
+ end
+
+ def cache_key
+ self.class.cache_key(source)
+ end
+
def self.find_or_create(source, url = nil)
- translation_domain = Tr8n::TranslationDomain.find_or_create(url)
- Tr8n::Cache.fetch("translation_source_#{translation_domain.id}_#{source}") do
+ Tr8n::Cache.fetch(cache_key(source)) do
+ translation_domain = Tr8n::TranslationDomain.find_or_create(url)
translation_source = where("source = ? and translation_domain_id = ?", source, translation_domain.id).first
translation_source ||= create(:source => source, :translation_domain => translation_domain)
translation_source.update_attributes(:translation_domain => translation_domain) unless translation_source.translation_domain
translation_source
end
end
def clear_cache
- Tr8n::Cache.delete("translation_source_#{translation_domain_id}_#{source}")
+ Tr8n::Cache.delete(cache_key)
end
end