Skip to content

Geocoder::CacheStore::Generic.new(Rails.cache, {})) does not support expiration #1670

Open
@Saoma1

Description

@Saoma1

Hello 👋

I've encountered an issue when using Geocoder::CacheStore::Generic.new(Rails.cache, {}) and passing an expiration in the cache_options. The @cache_hit is always true (after the first request). I expected @cache_hit to return false one the first request after the cache expired.

Upon reviewing the implementation here, it appears that expires_in is never passed to Rails.cache, which handles expiration logic.

I came across a related issue, but it focuses mainly on updating the documentation. Would it be possible to implement a proper Geocoder::CacheStore::RailsCache? This would eliminate the need for users to extend or monkey patch the gem.

For context, here is my configuration:

Geocoder.configure(
  timeout: 3, # geocoding service timeout (secs)
  lookup: :nominatim,
  language: :de, # ISO-639 language code
  use_https: true, # use HTTPS for lookup requests? (if supported)
  cache: Geocoder::CacheStore::Generic.new(Rails.cache, {}),
  cache_options: {
    expiration: 2.seconds
  },
  units: :km, # :km for kilometers or :mi for miles
)

I am happy to work on a PR!

Thank you for considering this! 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions