Class: Studio::Geo::Lookup::RailsCache

Inherits:
Object
  • Object
show all
Defined in:
lib/studio/geo/lookup.rb

Overview

Adapts Rails.cache to the []/[]= duck Geocoder's Generic cache store expects, adding the TTL that Rails.cache.write supports and Geocoder never passes.

Instance Method Summary collapse

Constructor Details

#initialize(ttl: 86_400) ⇒ RailsCache

Returns a new instance of RailsCache.



34
35
36
# File 'lib/studio/geo/lookup.rb', line 34

def initialize(ttl: 86_400)
  @ttl = ttl
end

Instance Method Details

#[](url) ⇒ Object



38
39
40
# File 'lib/studio/geo/lookup.rb', line 38

def [](url)
  ::Rails.cache.read(url)
end

#[]=(url, value) ⇒ Object



42
43
44
# File 'lib/studio/geo/lookup.rb', line 42

def []=(url, value)
  ::Rails.cache.write(url, value, expires_in: @ttl)
end