Skalar / google_distance_matrix

Ruby client for The Google Distance Matrix API.
MIT License
58 stars 45 forks source link

Filtered params break caching #41

Closed yoniamir closed 6 years ago

yoniamir commented 6 years ago

When I tried using the cache option provided by this neat gem, I was looking at my web requests and realized that requests are not being cached. Digging in, it appears that the write key and the read key to the cache differ. This happens because of the default filtering of the filter_parameters_in_logged_url setting, which excludes key from being written in the cache but is read from the cache, resulting in never working cache.

Setting the config.filter_parameters_in_logged_url = [] for example, fixes the caching problem. The obscuring does not work anyway since it's being used to read from the cache.

thhermansen commented 6 years ago

Thanks for reporting. I'll try to take a look this weekend.

Btw, have you written any code which exposes the problem in a test and fixed it? Feel free to submit a pull request if you have and I'll look at it.

yoniamir commented 6 years ago

Sorry, I've already changed so I don't have it handy- but if you put a log printing inside of client_cache.rb:16 you'll see that it gets called every new request to the server. It's also easy to see in the rails logs, the cache key being written is different from the cache key being read.

yoniamir commented 6 years ago

Google distance matrix api has become pretty expensive... :/

thhermansen commented 6 years ago

Hi,

I tried to reproduce it in tests, but I wasn't able to. Please take a look around here https://github.com/Skalar/google_distance_matrix/blob/80009225b259afbddbb52b0718195727c1544b03/spec/lib/google_distance_matrix/matrix_spec.rb#L141-L181

Are you able to write a test here which reproduces your reporting? Maybe you have a specific configuration or something? Please fork and write a test which exposes the situation.

Thank you.

thhermansen commented 6 years ago

Please feel free to reopen if you provide a branch with some failing spec which exemplifies it :)