How to save server side state using Snap Framework?

Server-side sessions are not yet included in the Snap Framework. Is there a way to add some kind of server-side state?

Suppose I want to increase the counter for each HTTP request. How should I do it?

+5
source share
3 answers

The easiest way is to put the state behind mvar:

fooHandler :: MVar Int -> Snap ()
fooHandler mvar = do
    x <- liftIO $ modifyMVar mvar $ \y -> let y'=y+1 in (y',y')
    writeBS $ S.pack $ "Incremented counter to: " ++ show x

Initialize mvar when initializing the site. Hope this helps.

+3
source

The above answer is correct as far as possible, but it does not address some real problems.

. , .

-, . Snap, 0,3 (, ), . , . // - , . .

0,3, . . PHP? ( , memcache, ). . ? .

, , , , . / , .

, , ( , ), 3 : , , , . , . : 3, init, , . , .

: - , . - showstack sqlite, , - , .

, "" , , Snap 0.3, MonadSnap.

+8

, :

snap-auth Snap Framework , , /contirbutor (Ozgun Ataman). . ByteString ByteString, , , ByteString:

type Session = Map ByteString ByteString

, mysnapsession . Map. . , , Snap Framework.

+1

All Articles