Class: Zipcoder::Cacher::Memory

Inherits:
Base
  • Object
show all
Defined in:
lib/zipcoder/cacher/memory.rb

Constant Summary

Constants inherited from Base

Base::KEY_BASE, Base::KEY_CITY, Base::KEY_COUNTY, Base::KEY_STATES, Base::KEY_STATE_CITIES, Base::KEY_STATE_COUNTIES, Base::KEY_ZIP

Instance Attribute Summary

Attributes inherited from Base

#loaded

Instance Method Summary collapse

Methods inherited from Base

#initialize, #iterate_cities, #iterate_zips, #load, #read_city_cache, #read_state_cities_cache, #read_state_counties_cache, #read_states, #read_zip_cache

Constructor Details

This class inherits a constructor from Zipcoder::Cacher::Base

Instance Method Details

#_empty_cacheObject



10
11
12
# File 'lib/zipcoder/cacher/memory.rb', line 10

def _empty_cache
  @cache.clear
end

#_init_cache(**kwargs) ⇒ Object



6
7
8
# File 'lib/zipcoder/cacher/memory.rb', line 6

def _init_cache(**kwargs)
  @cache = {}
end

#_iterate_keys(**kwargs, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zipcoder/cacher/memory.rb', line 22

def _iterate_keys(**kwargs, &block)
  return if block == nil

  start_with = kwargs[:start_with]

  @cache.keys.each do |key|
    if start_with == nil or key.start_with?(start_with)
      block.call(key)
    end
  end
end

#_read_cache(key) ⇒ Object



18
19
20
# File 'lib/zipcoder/cacher/memory.rb', line 18

def _read_cache(key)
  @cache[key]
end

#_write_cache(key, value) ⇒ Object



14
15
16
# File 'lib/zipcoder/cacher/memory.rb', line 14

def _write_cache(key, value)
  @cache[key] = value
end