Small patch to allow sessions to survive a reload

7 views
Skip to first unread message

Brenton

unread,
Sep 9, 2010, 11:43:48 AM9/9/10
to Ring
Hello group,

When using sessions and Ring's wrap-reload the session data is deleted
on each request. Is there a way around this without changing Ring?

If not, I have made a small change to ring-core/src/ring/middleware/
session/memory.clj to use defonce to define the session-map. See
http://github.com/brentonashworth/ring/commit/ebcdb3ec8adfc5c82d5fd6031f444a105701a8e0.

What do you think?

Brenton

Brenton

unread,
Sep 9, 2010, 11:50:39 AM9/9/10
to Ring
One more benefit/danger associated with this change is that it would
allow you to see what is in the session from the REPL. You can deref
session-map to view its contents. There have been several times in the
past when I have needed to do this and was not able to.

Brenton

On Sep 9, 8:43 am, Brenton <bashw...@gmail.com> wrote:
> Hello group,
>
> When using sessions and Ring's wrap-reload the session data is deleted
> on each request. Is there a way around this without changing Ring?
>
> If not, I have made a small change to ring-core/src/ring/middleware/
> session/memory.clj to use defonce to define the session-map. Seehttp://github.com/brentonashworth/ring/commit/ebcdb3ec8adfc5c82d5fd60....

James Reeves

unread,
Sep 9, 2010, 4:49:03 PM9/9/10
to ring-c...@googlegroups.com
I don't think we should implement this particular change, because
memory-store is a constructor; it is designed to return a new memory
store each time it is evaluated.

However, let me propose an equivalent change. The memory-store
function accepts an optional atom argument, allowing one to write:

(defonce my-atom (atom {}))

(def app (wrap-session handler (memory-store my-atom)))

Would that change meet your needs?

- James

Brenton

unread,
Sep 9, 2010, 5:31:46 PM9/9/10
to Ring
James,

That is much better. Yes, it meets both goals of being able to use
wrap-reload and being able to inspect session contents during
development. I just tried it out and also made changes to sandbar so
that options passed to wrap-stateful-session are passed on through to
wrap-session.

This is what I tried.

http://github.com/brentonashworth/ring/commit/7c9e921c3656b98265d35eb2d59f5735758f4c90

Here is an example usage (through sandbar):

http://github.com/brentonashworth/sandbar/blob/forms/src/sandbar/example/session_with_reload_demo.clj

Thanks James. This is a simple but great addition.

Brenton

On Sep 9, 1:49 pm, James Reeves <jree...@weavejester.com> wrote:
> I don't think we should implement this particular change, because
> memory-store is a constructor; it is designed to return a new memory
> store each time it is evaluated.
>
> However, let me propose an equivalent change. The memory-store
> function accepts an optional atom argument, allowing one to write:
>
>   (defonce my-atom (atom {}))
>
>   (def app (wrap-session handler (memory-store my-atom)))
>
> Would that change meet your needs?
>
> - James
>

James Reeves

unread,
Sep 11, 2010, 2:25:27 PM9/11/10
to ring-c...@googlegroups.com
I'll incorporate this into Ring right after 0.3.0 is released.

- James

Reply all
Reply to author
Forward
0 new messages