-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add caching #118
Comments
I think that's a great feature to have. |
@nicolas-brousse A caching option for VAT lookups with the caching option behind a proxy ala geocoder seems to be reasonable. I feel a slight hesitation for it, because strictly speaking it wouldn't be legally compliant to re-play the results of lookups. So I would prefer to choose the caching per lookup and default to direct lookups, so the behavior is transparent at least. But why would you like to cache the local validation? Or is there some misunderstanding? |
It depends on your use-case, but on our side we validate a VAT number only when it changes (not on every model save), and we save when was the last lookup performed in db. This way, we avoid double-checks and we can re-check periodically for old numbers. Even with a cache, you may end up getting rate-limit issues with some countries webservices if you have enough traffic, a lot of objects to backfill, etc Were it up to me, I'd add the ability to the lib to automatically save "last lookup performed at" (we currently use a callback that updates a timestamp column
|
@ksol It seems to me both of your examples are too specific and therefor would be out of the scope for this gem. It wouldn't make sense for me to abstract the required storage and background processing capabilities. This also violates rules in some member states regarding checking the VAT id every time before invoice creation. But: A simple caching solution – for short periods – when performing a lookup call would still be "nice to have". |
Hi!
We currently have some issues with usage of VIES API on one of our project because of their API have some issues.
It's not related to
valvat
gem which does its work correctly. But I was thinking of having some little cache to avoid calling too many time VIES API when not required.Since VAT validity does not change this often, I guess 1 or few hour of cache on a VAT number may not be risky.
I will take time to do a pull request, but I prefer to discuss here before doing some code.
One thing to have in mind is that this gem is not fully related to Rails and should work without it. So
Valvat::Lookup
objects may not be able to useRails.cache
(at least directly).So I've thing about 2 ways of doing caching:
Having a generic cache object (ex: https://github.com/alexreisner/geocoder#caching) that could be use as proxy for
Rails.cache
.Add a
cache: true
(orcache: 2.hours
) option in validator that may useRails.cache
.What do you think about it?
The text was updated successfully, but these errors were encountered: