0

I've just installed Memcached and I'd like to know if Memcached can cache images, js, css, font files, etc. on my server or it only works with scripting language?

Is it caching automatically or it have to be configured?

If not, how can I cache static files using PHP (exactly like variables values?)?

4 Answers 4

4

No, it doesn't, but there is also zero need to do this on a properly configured server: often accessed files on servers will be in the cache already / in memory buffers, and especially if they're static and you server has enough memory, will stay there for quite a while. Trying to serve them with Memcache will create MORE overhead, not less.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, I didn't know. So the best solution for that files is to not store them manualy in RAM? I forgot one more question. Is a good idea to store DB results for a while (these results are used for all users) and update them via crontab?
3

Your best option may be to use a caching layer like nginx for HTTP traffic (either as a proxy for apache or as the primary HTTP server). If you just want a proxy, Varnish is also a decent choice.

If you're stuck using Apache, here is a starting point for getting memory-based caching working: http://httpd.apache.org/docs/2.2/caching.html#inmemory

Also, you may want to look more into setting cache headers on your files so that multiple requests by the same users will not mean more file and network IO. This could be a bigger savings than explicitly caching things in memory as Linux will do some of that work for you.

2 Comments

I checked some questions ons stackoverflow and I saw that PHP APC is at least 5 times faster (for stored db results). Is it true? I'd like to speed up website as much as possible.
@ArturRychlewicz APC doesn't have to go through any drivers or network IO so using APC is good for some caching... If you have multiple PHP processes (likely), it will need to look up this data for each process before it is cached. Installing APC for speeding up your PHP runtime code is something you should definitely do though!
2

convert it to string and save it in memcache

<?php
  file_get_contents("/path/to/image.jpg");
?>

Comments

2

http://php.net/manual/en/book.memcached.php there is docs. You can save binary data, but efficient way to store complex data generated, like DB-results

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.