Artur Rychlewicz
Artur Rychlewicz

Reputation: 505

Is Memcached caching static files like images, css, js..?

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?)?

Upvotes: 0

Views: 5354

Answers (4)

Mark Caudill
Mark Caudill

Reputation: 134

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.

Upvotes: 3

nkt
nkt

Reputation: 75

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

Upvotes: 2

Wrikken
Wrikken

Reputation: 70510

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.

Upvotes: 4

Ahmed Abumostafa
Ahmed Abumostafa

Reputation: 218

convert it to string and save it in memcache

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

Upvotes: 2

Related Questions