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.

Nginx or memcache for caching static files?

Discussion in 'Nginx' started by ASTRAPI, Jan 12, 2011.

  1. #1
    Hello

    I am using a cpanel server and i have nginx plugin in front of Apache and i use also xcache for php opcode caching.

    Now i want to find the best way to cache static files and i have two options in my mind.

    1)Adding a few lines on my nginx config so it will cache static files.

    In this case which lines i must add and where exactly in my config?

    How nginx will know when to clear cache and don't give me a huge cache folder and make worst my server performance?

    2)Install memcache.

    Here i am confused on memcache and memcached as i don't know which one is for static files and not for php caching as i have already xcache for php caching and if i must install both to get static files caching only.

    Thank you
     
    ASTRAPI, Jan 12, 2011 IP
  2. Martindale

    Martindale Well-Known Member

    Messages:
    440
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    108
    #2
    It depends on your constraints; if you want to do forced cache invalidation, memcache is a great option. If not, then creating a file/memory cache in nginx is more than sufficient. It is not likely that you'll run into issues with this at normal volumes.
     
    Martindale, Feb 5, 2013 IP
  3. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #3
    If the files are already static, caching them isn't going to make a huge difference unless you are disk i/o bound (which I highly doubt).

    If you explained a little more about what you are trying to achieve in the end, we could probably help a little more. What problem do you have currently that you are trying to solve with static file caching?
     
    digitalpoint, Feb 6, 2013 IP
  4. CheetahNode

    CheetahNode Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    If you face I/O issues on accessing small static files, caching helps some times. For dynamic contents caching, Memcache is good
     
    CheetahNode, Feb 11, 2013 IP
  5. Hostname.club

    Hostname.club Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    90
    Digital Goods:
    11
    #5
    Be careful! Sometimes nginx will stop working. To control nginx, you will learn more. :)
     
    Hostname.club, Feb 16, 2013 IP
  6. mlazarov

    mlazarov Active Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    66
    #6
    What's your currect nginx proxy configuration?
     
    mlazarov, Aug 21, 2013 IP
  7. amcd

    amcd Active Member

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #7
    For the best performance, you should not cache static files. Any linux / BSD server will automatically cache frequently accessed files if memory is available. You should use "sendfile on" in nginx. You may want to compress js and css files. Look at the gzip_static module.

    http://wiki.nginx.org/HttpCoreModule#sendfile
    http://wiki.nginx.org/HttpGzipStaticModule

    Regarding your second option, memcached is not for caching files. It can be used for this, but that is not what it was designed for. It is for caching variables and database results.

    Memcached is the memcache daemon. They are used interchangeably in conversation. The confusion arises from the fact that php has two extensions for connecting to memcached. They are, most annoyingly, called pecl_memcache and pecl_memcached.
     
    amcd, Sep 25, 2013 IP