News:

Support the VirtueMart project and become a member

Main Menu

Custom Feature Proposal - rate caching

Started by lowmips, December 18, 2008, 21:45:27 PM

Previous topic - Next topic

lowmips

Hi all,
I'm sure you are all painfully aware of the USPS API servers being down over the past few weeks, and I have thought of an additional feature which may alleviate some pain in the future should this happen again.  My idea is to use a rate caching system.  My UPSv2.0 module currently uses a simple (but temporary) caching system and I would like to expand that idea to a more robust version to use with both the UPS and USPS modules.  It would work something like this:

Anytime your website requests a rate from USPS, it would store the results locally in your MySQL database.  It would store weight, source/dest zip codes, insurance options, price, and possibly some other variables.  Then, when your website needs to request a rate again, it first checks the database to see if a cached version with the same parameters already exists.

I would include a cache "aging" mechanism, totally configurable by you, to ensure that any rates are updated as actual shipping costs change.  For example, you may wish to set the cache to 7 days.  After the cached rate entry has expired, any further call for a rate request using those same variables would be sent to the USPS API servers, and the "fresh" rate would be cached in its place.  I would also include a "purge" option so that if you know a specific date that rates will be changing, you could purge the entire cache on that day and begin caching the new rates.

I believe this option would benefit large traffic websites in terms of response time, as the rate requests go locally to the database instead of out to the internet.  It also benefits you in reduced bandwidth usage. But mainly, this feature would provide a backup mechanism in case the USPS servers are not responding.
Smaller websites may not benefit as much because if they have low traffic, not many rates would be cached.  Determining whether or not to use the cache is left as an exercise to the user ;).

I have also thought about a "best guess" system for when the USPS servers are down, and a specific cached rate does not exist.  The "best guess" system would use existing similar cached rates to guestimate a rate to use.  For example, if the cache has a rate for a 10lb item, a 20lb item, both sent to the same zip code, but you need a rate for a 15lb item, the system would guess based on the average of the two prices.  Any feedback for how to make the best guesses would be appreciated.

I would like to implement this feature, and I am looking for donators willing to pay for my time in doing so.  I estimate that it will take a ballpark of 10-15 hours to code/debug/test the basic caching system.  I'm unsure of how long the "best guess" system would take, and will only implement it if enough people show an interest. 

If you would like to see either of these features implemented in my USPSv5.0 module please email (ogre at lowmips dot com) or private message me with the amount you are willing to donate.  Once enough donators have shown interest, I will write the code and release it to the VirtueMart forums for all to use.

Thank you,
Reggie

Visit my website at www.lowmips.com
View my newsletters Here (sign up for newsletters on the front page of my website)