Click to See Complete Forum and Search --> : efficient cache management for storing phone numbers


ankursaxena
October 17th, 2002, 11:33 AM
Hi! I have a small problem, more than a language construct problem this is a logical problem, I have a soft switch which talks to me to get authorization for a phone call to go through. Now the data is stored in the database and each time a phone call is made, i have to make the call to the database, which is kind of expensive. Now what i want is to distribute my current logic which contains everything into:

Authorization Controller, Database Manager, Cache Manager.

Now when a request comes from the softswitch, i first check the cache manager and if it doesnt exists then query the mysql manager, and get my data. Now i take this data and replace it with the oldest record in cache. this is done by the cache manager itself.

Does this sound like a good plan, or something better can be used. It would be great if someone could help me on that. But the main problem is that i have to design the cache manager, now I dont know what data structure to use to manage these phones numbers, should I use a plain array, or a balanced tree or hash table, the numbers are going to be random, so just throwing that in, if that helps, but the numbers associated with a particular autharization controller would be in sequence like 8472851000-8472851999 and 847xxxyyyy-847xxxzzzz(both with 1 AC)

Also the data stored in the cache would not only contain the phone number, but also some settings which are required frequently, so a single entry of a phone number would be close to 1k.

Thanks for all the help.

Regards,

Ankur

JMS
October 17th, 2002, 12:23 PM
I would use a hash for the cache look up, it's fast using pointers in you're hash it won't take all that much memory to have a host a pretty wide range of numbers..

I would use a link list with timestamps which pointed to the hashed nodes so I could quickly lay my hands on the old phone numbers which I wished to return to the DB as I stored newer numbers.

I think it would be pretty easy to get this working and it would smoke performance wise.... Be a little tricky zapping out the hash table after you've expired an entry, but this again could be done since you'll know the hash value if you have the node....

Good luck..