Sha256: 269ec78765f0d30010d4454ce70597f6bdd9f4ee843bb4c2d6091115d355af96

Contents?: true

Size: 1.15 KB

Versions: 21

Compression:

Stored size: 1.15 KB

Contents

module Mobility
  module Plugins
    module Cache
=begin

Creates a module to cache a given translation fetch method. The cacher defines
private methods +cache+ and +clear_cache+ to access and clear, respectively, a
translations hash.

This cacher is used to cache translation values in {Mobility::Plugins::Cache},
and also to cache translation *records* in {Mobility::Backends::Table} and
{Mobility::Backends::KeyValue}.

=end
      class TranslationCacher < Module
        # @param [Symbol] fetch_method Name of translation fetch method to cache
        def initialize(fetch_method)
          class_eval <<-EOM, __FILE__, __LINE__ + 1
            def #{fetch_method} locale, **options
              return super(locale, options) if options.delete(:cache) == false
              if cache.has_key?(locale)
                cache[locale]
              else
                cache[locale] = super(locale, options)
              end
            end
          EOM

          include CacheMethods
        end

        module CacheMethods
          private
          def cache;       @cache ||= {}; end
          def clear_cache; @cache = {};   end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
mobility-0.8.13 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.11 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.10 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.9 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.8 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.7 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.6 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.5 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.4 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.3 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.2 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.1 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.8.0 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.7.6 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.7.5 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.7.4 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.7.3 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.7.2 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.7.1 lib/mobility/plugins/cache/translation_cacher.rb
mobility-0.7.0 lib/mobility/plugins/cache/translation_cacher.rb