Class: FastGettext::Cache

### Home Classes Methods

### In Files

- lib/fast_gettext/cache.rb

### Parent

Object

### Methods

- ::new
- #[]=
- #delete
- #fetch
- #reload!
- #switch_to

### Class/Module Index

Quicksearch

- FastGettext
- FastGettext::Cache
- FastGettext::GetText
- FastGettext::GetText::MOFile
- FastGettext::GetText::MOFile::HeaderRev1
- FastGettext::GetText::MOFile::InvalidFormat
- FastGettext::GetText::PoParser
- FastGettext::MoFile
- FastGettext::PoFile
- FastGettext::Storage
- FastGettext::Storage::NoTextDomainConfigured
- FastGettext::Translation
- FastGettext::TranslationMultidomain
- FastGettext::TranslationRepository
- FastGettext::TranslationRepository::Base
- FastGettext::TranslationRepository::Chain
- FastGettext::TranslationRepository::Db
- FastGettext::TranslationRepository::Logger
- FastGettext::TranslationRepository::Mo
- FastGettext::TranslationRepository::Po
- FastGettext::TranslationRepository::Yaml
- String
- TranslationKey
- TranslationText

No matching classes.

# FastGettext::Cache

### Public Class Methods

new() click to toggle source

    # File lib/fast_gettext/cache.rb, line 3
    def initialize
      @store = {}
      reload!
    end

### Public Instance Methods

[]=(key, value) click to toggle source

TODO only used for tests, maybe if-else around it ...

    # File lib/fast_gettext/cache.rb, line 18
    def []=(key, value)
      @current[key] = value
    end

delete(key) click to toggle source

    # File lib/fast_gettext/cache.rb, line 33
    def delete(key)
      @current.delete(key)
    end

fetch(key) click to toggle source

    # File lib/fast_gettext/cache.rb, line 8
    def fetch(key)
      translation = @current[key]
      if translation.nil? # uncached
        @current[key] = yield || false # TODO get rid of this false hack and cache :missing
      else
        translation
      end
    end

reload!() click to toggle source

    # File lib/fast_gettext/cache.rb, line 37
    def reload!
      @current = {}
      @current[""] = false
    end

switch_to(text_domain, locale) click to toggle source

key performance gain:

- no need to lookup locale on each translation

- no need to lookup text_domain on each translation

- super-simple hash lookup

    # File lib/fast_gettext/cache.rb, line 26
    def switch_to(text_domain, locale)
      @store[text_domain] ||= {}
      @store[text_domain][locale] ||= {}
      @store[text_domain][locale][""] = false # ignore gettext meta key when translating
      @current = @store[text_domain][locale]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.