-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use SessionStore? #108
Comments
To implement a custom SessionStore, you'll have to "fill" this data-type: data SessionStore sess tx
= SessionStore
{ ss_runTx :: forall a. tx a -> IO a
, ss_loadSession :: SessionId -> tx (Maybe sess)
, ss_deleteSession :: SessionId -> tx ()
, ss_storeSession :: sess -> tx ()
, ss_toList :: tx [sess]
, ss_filterSessions :: (sess -> Bool) -> tx ()
, ss_mapSessions :: (sess -> tx sess) -> tx ()
} You can take a look here for the implementation of the default STM session store. Basically, a
|
Thanks, that helps. I was a bit overwhelmed because it looked a lot more complicated than just the pair of load/store functions in the older versions of Spock. Is there a specific reason the readShowSessionPersist is no longer available? Let's say, if I would implement it, would you want to add it to the code base? Also, is there a way to use a SpockAction monad as tx? Because it seems a bit unpleasant to open a separate database connection (for example in the IO monad), when Spock already has a set-up for the connection in place. But at the same time I think the SpockAction monad depends on the SessionStore, right? |
I personally never used the readShowSessionPersist and wasn't aware that anyone used it. If you like to add it back it would make sense to have it sit on top of the Currently there is not since the |
Ah ok. I just noticed that it existed, and I think it's an easy way to get persistent sessions in a dev environment (like now, I often restart my spock app, and it forgets that I'm logged in so I have to go through that process for testing, which takes time). Having to "derive (Read, Show)" on your session type is a much smaller up-front investment than implementing a whole session storage system. If the way you suggest could be both persistent and performant I think that could actually be a valuable addition (maybe then it would be realistic to avoid using the database for persistence altogether). I'm not sure what you mean about abstracting over read and show though. With passing the database down to the SessionStore, you mean generating it with a function of PoolOrConn a, passing it the same instance that's also used to configure SpockAction? |
By abstracting over read and show I meant that instead of using No. If you look at Web.Spock then all |
Hello, I tried to write custom SessionStore for Redis https://github.com/elephanter/spock-session-redis |
Oh, nice! I think you can implement your custom |
There seems to be little documentation other than the types :)
I want to make my sessions persistent, I was hoping I could just use readShowSessionPersist (for a development environment) but it seems that in the version I'm using (0.11.0.0) that has been removed. Do you have an example implementation?
The text was updated successfully, but these errors were encountered: