4

Is there any theory that says that a cache should be faster than a file system?

I think that since the file system also uses caching there is no scientific proof that we should move content from file system to a cache such as memcache when the concept of file system is somewhat loose -- like downloading a "file" could be the same as downloading a memcached object.

My concrete example is whether to host a template engine via memcache or file system. Does it matter?

agf
  • 171,228
  • 44
  • 289
  • 238
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
  • 4
    memcache is optimized for one purpose. A filesystem is optimized for many. – agf Aug 25 '11 at 20:19
  • I tried comparing cache with SQL and the difference in favor of cache was large. But slow database ould be an explaining factor and I don't rule out that a fast file system can be just as fast or faster than memcache. I ask since sometimes I've got the option to either store something in memcache or in file system and a file system could be very fast and I think I could serve a filesystem using memcache – Niklas Rosencrantz Aug 25 '11 at 20:43

2 Answers2

8

Your filesystem will probably be faster in many situations. E.g. when you need a cache for your "compiled templates", the filesystem will be faster.

And the filesystem caches (especially on linux) will make sure, that your cached templates - which are read often - are available in very short time. The kernel keeps them in an in-memory cache, and reads will be fast as hell.

memcached is a distributed key/value store. It has different use cases.

Frunsi
  • 7,099
  • 5
  • 36
  • 42
4

Please read the memcached about page to understand why memcached exists. Your question doesn't make sense unless you have a magical clustered filesystem cache for your 100 front-end web servers.

Dustin
  • 89,080
  • 21
  • 111
  • 133
  • Thank you for the link. "speeding up dynamic web applications by alleviating database load" is not the same as serving static files. So I understand it's very good that I can save a query since I won't have to go to the data layer next time. But to save a file? Serving files from file system seems fast if not faster and if I want to serve just a basic file e.g. CSS or javascript file, isn't file system still a good choice or if I want optimization should I even use memcache if content doesn't change? – Niklas Rosencrantz Aug 25 '11 at 20:49
  • memcached isn't a file cache. If you're wanting a content server, you should look into varnish or similar. If you have just one server and the files it's serving all fit within your filesystem cache, you probably don't have a problem and it's not worth it to try to find a solution. – Dustin Aug 25 '11 at 23:49