how to cache contents in HAProxy [closed]

don't use the wrong tool

haproxy is a wonderful tool. It does not provide caching. A quick scan of the fine docs can verify this. Unless you want to patch haproxy you need to use a tool that does what you're looking to do.

don't create impossible problems

By asking for haproxy to do something that it doesn't and excluding the tool that seems to do what you want to do you've create an impossible situation. There is no technical solution for this. Don't make choices that box you into a corner.

try varnish or anything that actually caches

If you get over that you might find this tutorial on using varnish with haproxy useful or try varnish by itself. Maybe squid or memcached would be more your speed.