Caching 404s - NGINX or Varnished?

view story

http://serverfault.com – I'm looking for a solution to cache 404s in long term (a few days/weeks) on the webserver. My current setup is NGINX with memcached_pass proxy and PHP-FPM to deliver uncached pages (PHP also writes the contents to memcached). The crawlers all around the web seem to like my pages and generate a few thousand 404 requests a day. All of them hit PHP directly since I can't cache 404 response header informations together with the contents in memcached, hence the memcached_pass lookup always fails. How can I cache all those requests that return a 404? Is the HTTPProxModule for Nginx what I'm looking (HowTos)