session icon indicating copy to clipboard operation
session copied to clipboard

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

Open mavidser opened this issue 6 years ago • 2 comments

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 avatar Aug 02 '19 07:08 mavidser

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.

mavidser avatar Aug 02 '19 07:08 mavidser

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.

unknwon avatar Aug 04 '19 21:08 unknwon