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
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.
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?
If you face I/O issues on accessing small static files, caching helps some times. For dynamic contents caching, Memcache is good
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.