Browse Source

Merge branch 'master' of github.com:yogsototh/wai-middleware-caching

master
parent
commit
5157c09bd7
  1. 16
      wai-middleware-caching/src/Network/Wai/Middleware/Cache.hs
  2. 3
      wai-middleware-caching/wai-middleware-caching.cabal

16
wai-middleware-caching/src/Network/Wai/Middleware/Cache.hs

@ -13,7 +13,8 @@ import qualified Data.ByteString.Lazy as LZ
import Data.IORef
import Network.Wai (Middleware, Request, Response,
requestBody, responseToStream,
mapResponseHeaders)
responseStatus, mapResponseHeaders)
import Network.HTTP.Types.Status (statusCode)
--------------------------------------------------------------------------------
-- | The data structure that should contains everything you need to create
@ -87,10 +88,15 @@ addToCacheAndRespond :: CacheBackend cc ck cv
-> Response
-> IO b
addToCacheAndRespond cb sendResponse req key r = do
cacheVal <- responseToCacheVal cb r
addToCache cb (cacheContainer cb) key cacheVal
actionOnCacheMiss cb req r
sendResponse (cacheValToResponse cb cacheVal)
let code = statusCode (responseStatus r)
if (code >= 200) && (code < 400)
then do
cacheVal <- responseToCacheVal cb r
addToCache cb (cacheContainer cb) key cacheVal
actionOnCacheMiss cb req r
sendResponse (cacheValToResponse cb cacheVal)
else
sendResponse r
getRequestBody :: Request -> IO (Request, S8.ByteString)
getRequestBody req = do

3
wai-middleware-caching/wai-middleware-caching.cabal

@ -1,5 +1,5 @@
name: wai-middleware-caching
version: 0.1.0.1
version: 0.1.0.2
synopsis: WAI Middleware to cache things
description: Please see README.md
homepage: http://github.com/yogsototh/wai-middleware-caching/tree/master/wai-middleware-caching#readme
@ -20,6 +20,7 @@ library
, blaze-builder
, bytestring
, wai >= 3.0
, http-types
default-language: Haskell2010
test-suite wai-middleware-caching-test

Loading…
Cancel
Save