wai-middleware-cache-redis-0.1.0: Redis backend for wai-middleware-cache

Safe HaskellSafe-Infered

Network.Wai.Middleware.Cache.Redis

Contents

Description

Redis backend for Network.Wai.Middleware.Cache.

This backend uses Database.Redis.Pile for low-lewel operations.

 cache
     (redisBackend 
         -- use defaults, DB 0 and "myprefix" 
         R.defaultConnectInfo 0 "myprefix"
         (const Nothing)    -- no expiration
         (const ["mytag"])  -- simply one tag "mytag"
         (rawPathInfo)      -- URL path as key 
         lookupETag         -- And find "If-None-Match"
     ) app -- our app

Synopsis

Cache backend

redisBackendSource

Arguments

:: ConnectInfo

Redis connection info.

-> Integer

Redis DB.

-> ByteString

Cache prefix for key and tags. See Database.Redis.Pile for details.

-> (Request -> Maybe Integer)

TTL extraction. Use Nothing for no expiration.

-> (Request -> [ByteString])

Tags extraction. See Database.Redis.Pile for details.

-> (Request -> ByteString)

Key extraction.

-> (Request -> Maybe ByteString)

ETag value extraction. To extract If-None-Match header use lookupETag. Use (const Nothing) for block 304-responses.

-> CacheBackend 

Redis backend for Network.Wai.Middleware.Cache.

Except caching, this backend always adds ETag to Response headers with hexed SHA1 as value.

Helpers

lookupETag :: Request -> Maybe ByteStringSource

Helper for extract If-None-Match header from Request.