Class: Mova::Storage::Memory
- Inherits:
-
Object
- Object
- Mova::Storage::Memory
- Defined in:
- lib/mova/storage/memory.rb
Overview
Note:
This class was designed to be not thread-safe for the sake of speed. However, if you store translations in static YAML files and do not write to the storage during application runtime, this is not a big deal.
If you need thread-safe in-memory implemenation, use ActiveSupport::Cache::MemoryStore.
Also note that with any in-memory implementation you’ll have a copy of all translations data in each spawned worker. Depending on number of your locales, translation keys and workers, it may take up a lot of memory. This is the fastest storage though.
Thin wrapper around Hash.
Instance Method Summary collapse
- #clear ⇒ void
- #exist?(key) ⇒ Boolean
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #read(key) ⇒ String?
- #read_multi(*keys) ⇒ Hash
- #write(key, value) ⇒ void
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
20 21 22 |
# File 'lib/mova/storage/memory.rb', line 20 def initialize @storage = {} end |
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
57 58 59 |
# File 'lib/mova/storage/memory.rb', line 57 def clear @storage.clear end |
#exist?(key) ⇒ Boolean
52 53 54 |
# File 'lib/mova/storage/memory.rb', line 52 def exist?(key) @storage.key?(key) end |
#read(key) ⇒ String?
26 27 28 |
# File 'lib/mova/storage/memory.rb', line 26 def read(key) @storage[key] end |
#read_multi(*keys) ⇒ Hash
36 37 38 39 40 41 |
# File 'lib/mova/storage/memory.rb', line 36 def read_multi(*keys) keys.each_with_object({}) do |key, memo| result = read(key) memo[key] = result if result end end |
#write(key, value) ⇒ void
This method returns an undefined value.
46 47 48 |
# File 'lib/mova/storage/memory.rb', line 46 def write(key, value) @storage[key] = value end |