I want to implement emails blacklist for my system. In that list I would like to store emails which are not deliverable.
When my system can't deliver email, I would like to save it, and later never send them again.
There are two possible easiest solution what I could see:
When recipient is non exist,
- I could set mark about that in User table
- Or collect such bad emails in specific table
2nd solution is more easiest seems to me (because easier can be cached), but there is a question about choosen approach...
In MyMail function I will implement a call to search current email in bad emails list (table) first and then if it is not there send it out, otherwise cancel sending.
So main question what is could be faster:
1. Making query each time to DB to search particular key like, SELECT 1 FROM table WHERE email='checking_email'
. And of course that table will have only one field email
and that field will be indexed(unique). And I will use only strict comparision.
2. or cache that table content in ONE array and making query to array to check is particular element|key exist or not ?
In case when bad email list could be as long as much, for example 10 million records.
What will be faster ? and better for high loading project ?
P.S. I know that PHP array's eat too much memory, But doing a lot of DB queries in case when newsletter sending is started is also not so good.
P.P.S. I'm going to cache bad emails in one variable this is why in PHP it will be present as array.
P.P.S. Another approach is caching each bad email in each cache key and checking only if such key exist in cache or not, but in that case purging the cache will be more complicated. I'm thinking this is the best solution. Keys in cache can be like, bad_email_. And logic of that pre sending call could be: check if required email exist in cache, if not exist, then check in DB if it is not present and there too, then it is good email. From other point if system detect bad email then it will be saved in DB and in Cache in the same time.