Class: Ip2Geo::Helpers::Cache
- Inherits:
-
Object
- Object
- Ip2Geo::Helpers::Cache
- Defined in:
- lib/ip2geo/helpers/cache.rb
Class Method Summary collapse
Class Method Details
.clear ⇒ Object
33 34 35 36 37 38 |
# File 'lib/ip2geo/helpers/cache.rb', line 33 def clear @mutex.synchronize do @store = {} @access_order = [] end end |
.get(key) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ip2geo/helpers/cache.rb', line 9 def get(key) @mutex.synchronize do entry = store[key] return nil unless entry if expired?(entry) store.delete(key) access_order.delete(key) return nil end update_access_order(key) entry[:data] end end |
.set(key, data) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/ip2geo/helpers/cache.rb', line 25 def set(key, data) @mutex.synchronize do store[key] = { data: data, timestamp: Time.now.to_f } update_access_order(key) evict_if_needed end end |