Database caching can be a reason of data redundancy
Database caching brings the convenience of result set already fetched and stored in files. I am sharing a situation which i faced twice but still i sometimes forget to avoid. The thing is to validate a record in database that either it exists or not? If it exists then update this record and if it is not exists then insert. For example, if database caching returns that there is no record with this where clause so you will take the decision of insertion instead of updating it. By this you will be inserting the same record again and again because your SELECT QUERY will be returning the same results. The solution is simple that don’t cache that particular query because of its importance else you will face data redundancy. If you ever see the websites which are based on news etc. you will notice that few news are replicated or displayed many times. The reason behind is the database caching because such websites are having cron job scripts to keep them updated with RSS Feeds or some APIs. When the script check the database that this particular news already exists or not so it decides to insert that news as for the first time. By insertion, we see the replication of the same news again and again. Most of the web developers don’t think about that, in greed of lesser load time a web developer can go far as much as he can. He might cache the files through .htaccess and also turn on the database caching. Hats of to those developers who keep in mind to turn off the caching before running some important queries.
Last updated: March 19, 2014