Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
Saoma1 opened this issue Nov 20, 2024 · 1 comment

Comments

@Saoma1
Copy link

Saoma1 commented Nov 20, 2024

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! 😊

@alexreisner
Copy link
Owner

Good point. I think this was done because we didn't want to make it seem like expiration is supported by cache back-ends that don't actually support it. But yes, I'm open to a PR For a proper Rails cache solution. (Thanks!)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants