Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While working on #287 I came to realize that the credentials cache shouldn't override the user key with a list of sessions, but instead should add another key that can be looked up with the namespace. There is potential race condition issue when overriding the key, and it may only happen when updating the user cache key (since we never guarantee that the user is the most recent updated, but do have to guarantee that all sessions are listed).
This can still be done with a binary keys with namespace, but to improve efficiency I've moved over to Erlang terms for keys for namespace so match spec can be used. In Pow either a binary key or a list consisting of binary, integer or atom is used as key and will always in the cache backend be wrapped in a list with a prepending namespace.
Pow.Store.CredentialsCache
now inserts three keys at once, which in ETS and Mnesia is guaranteed to be atomic:Instead of the previous:
I've also refactored the code so the cache store and cache backend has separate behaviours.
The Redis guide has be updated, and I've added a bunch of backwards compatibility logic since there are many who uses Redis with binary key in production at the moment.
Any extra 👀 or hands to test this out would be much appreciated!
Resolves #302