Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
1  init.rb
@@ -6,6 +6,7 @@
# Load globalize libs
require "globalize/localization/db_view_translator"
+require "globalize/localization/db_view_translator_memcache"
require "globalize/localization/rfc_3066"
require "globalize/localization/locale"
require "globalize/localization/supported_locales"
View
61 lib/globalize/localization/db_view_translator_memcache.rb
@@ -0,0 +1,61 @@
+require 'memcache'
+require 'digest/md5'
+
+module Globalize # :nodoc:
+ class DbViewTranslatorMemcache < DbViewTranslator
+ SERVERS = "localhost:11211"
+ NAMESPACE = "globalize"
+
+ def cache_count
+ end
+
+ def cache_reset
+ end
+
+ private
+
+ def cache_fetch(key, language, idx, namespace = nil)
+ k = cache_key(key, language, idx, namespace)
+ begin
+ @cache.get(k)
+ rescue MemCache::MemCacheError
+ initialize
+ @cache.get(k)
+ end
+ end
+
+ def cache_add(key, language, idx, translation, namespace = nil)
+ k = cache_key(key, language, idx, namespace)
+ begin
+ @cache.add(k, translation)
+ rescue MemCache::MemCacheError
+ initialize
+ @cache.add(k, translation)
+ end
+ end
+
+ def invalidate_cache(key, language, idx, namespace = nil)
+ k = cache_key(key, language, idx, namespace)
+ begin
+ @cache.delete(k, namespace)
+ rescue MemCache::MemCacheError
+ initialize
+ @cache.add(k, translation)
+ end
+ end
+
+ def cache_key(key, language, idx, namespace = nil)
+ Digest::MD5.hexdigest([key, language.code, idx, namespace].compact.join(':'))
+ end
+
+ def cache_hit_ratio
+ end
+
+ def cache_clear
+ end
+
+ def initialize()
+ @cache = MemCache.new(SERVERS, :namespace=>NAMESPACE)
+ end
+ end
+end
View
5 lib/globalize/localization/locale.rb
@@ -23,6 +23,11 @@ class Locale
@@base_language_code = nil
@@translator = @@translator_class.instance
+ def self.translator_class=(klass)
+ @@translator_class = klass
+ @@translator = @@translator_class.instance
+ end
+
# Is there an active locale?
def self.active?; !@@active.nil? end
View
1  lib/globalize/rails/action_view.rb
@@ -32,6 +32,7 @@ def path_and_extension(template_path) #:nodoc:
def locate_globalize_path(template_path, use_full_path)
active_locale = Globalize::Locale.active
locale_code = active_locale.code
+ template_format ||= :notemplate # for older version of ActionView
cache_key = "#{locale_code}:#{template_path}:#{template_format}"
cached = @@globalize_path_cache[cache_key]
return cached if cached

No commit comments for this range

Something went wrong with that request. Please try again.