We used httpcache library to implement this. As it was not possible to support different policies, I mostly copied and modified it.