1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Which is better to use DB or Cache?

Discussion in 'Databases' started by abhicyco, Dec 18, 2013.

  1. #1
    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 !!
     
    Solved! View solution.
    abhicyco, Dec 18, 2013 IP
  2. khodem

    khodem Well-Known Member

    Messages:
    206
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    120
    #2
    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
     
    khodem, Dec 18, 2013 IP
  3. abhicyco

    abhicyco Active Member

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #3
    What you are saying is true, but how about caching? You didn't mentioned anything about it.
     
    abhicyco, Dec 18, 2013 IP
  4. #4
    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
     
    khodem, Dec 18, 2013 IP
  5. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #5
    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
     
    crivion, Dec 19, 2013 IP