go-macaron / session

Package session is a middleware that provides the session management of Macaron.
Apache License 2.0
26 stars 27 forks source link

Flush() or Delete() doesn't work in mysql #30

Open mavidser opened 5 years ago

mavidser commented 5 years ago

memory provider works fine, but if I use mysql - it basically seems to be a no-op with no queries executed. The session is changed in memory, but doesn't write to the database.

Currently using Set('key', '') and Destory(ctx) to perform these operations, but doesn't seem to be the right way.

mavidser commented 5 years ago

Reading through the code, it looks like Release() checks if len(s.data) == 0 { return nil }

So, if I just had one key which I deleted, it doesn't get persisted.

Same case for Flush() too probably; unless, I have the wrong idea of what Flush() is supposed to do.

This issue seems to be a thing among other providers too. If confirmed, I can probably start working on a PR in the coming week.

unknwon commented 5 years ago

Thanks for the feedback!

I think you're right, probably just remove code block that checks for len(s.data) == 0?

https://github.com/go-macaron/session/blob/d2c984b2801fbcd84b925838628e39d18649846a/mysql/mysql.go#L80-L83

Flush() is meant to remove every key but still need to wait until Release to save to its persistent location.