Transparent front cache middleware for
Instead caching internal data, this middleware caches entire responses. Of course, this creates additional costs. However, the simplification of the internal structure and concentration of caching in the immediate vicinity of the request is more than redeem them.
cache (debugBackend True) ourFrivolousApplication
Abstract cache backend. Result may be
Nothing you need to respond
304 - Not Modified.
Cache backend can throw errors. For handle this, use, for example, Network.Wai.Middleware.Catch.
-- Simplest backend. Suggests @304 - Not Modified@ with site root. rootBackend app req = do case rawPathInfo req of "/" -> return Nothing _ -> do res <- app req return $ Just res app = responseLBS ok200  "someresponse" cachedApp = cache rootBackend $ headerETag $ app
Add "ETag" header to response if it not present. Value of header is
MD5 hash of response body.