I am working on a task where I have to fetch data from api. Data is updated very frequently. I want to put up a wall in between data fetched from api and data displayed on webpage. Which is better option DB or cache(memcache)? Please help !!
Combination of both will give you robust speed and control, and less resource usage as once it's accessed from db it will cached and then only new request or updated data will be asked from database... if you can use both it will be better or else use Database... but only using database won't give you much speed you need to optimize database on data level and plus you have to optimize your database against the query you are have... best of luck
But it depends on the volume of the data your playing... if it's big file and you do many read/write and cache is problem... if it's small amount of transaction then go for cache but in case of cache you will not be having any record of data it's cached in memory... but in database you can keep the data as long as you want... in cache sometimes you depend on user if they cleaned browser cache it's gone! but in database it's not
I recommend memcached if you have multiple servers otherwise PHP APC will do its job. Let's see: 1) database will provide you a way to query the data 2) caching (memcached/apc/etc) will not provide you a way to query, just fetch the data based on the previously saved key. So it depends, if you need to do queries (like by date, title, etc) use both: mysql + memcached/apc. If you don't need any queries, memcached/apc will do it very well I personally like php apc because its also an opcode cache and speeds up the php execution