Skip to content

Commit

Permalink
feat: remove authentiacation cache
Browse files Browse the repository at this point in the history
Signed-off-by: xdlbdy <xdlbdy@gmail.com>
  • Loading branch information
xdlbdy committed Mar 30, 2023
1 parent ba347ae commit 3d65f2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion internal/primitive/authentication/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ func (a *authentication) checkTokenExpired() {
}

func (a *authentication) Authenticate(ctx context.Context, token string) (string, error) {
/* remove cache
v, exist := a.tokens.Load(token)
if exist {
return v.(string), nil
}
*/
// todo breakdown cache
user, err := a.client.GetUser(ctx, token)
if err != nil {
Expand All @@ -94,6 +96,6 @@ func (a *authentication) Authenticate(ctx context.Context, token string) (string
if user == "" {
return "", errors.ErrResourceNotFound.WithMessage("token is invalid")
}
a.tokens.Store(token, user)
// a.tokens.Store(token, user)
return user, nil
}
12 changes: 6 additions & 6 deletions internal/primitive/authentication/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func TestAuthentication_Authenticate(t *testing.T) {
ctx := context.Background()
m := NewAuthentication(tokenClient).(*authentication)
token := "test"
Convey("cache exist", func() {
m.tokens.Store(token, "user")
user, err := m.Authenticate(ctx, token)
So(err, ShouldBeNil)
So(user, ShouldEqual, "user")
})
// Convey("cache exist", func() {
// m.tokens.Store(token, "user")
// user, err := m.Authenticate(ctx, token)
// So(err, ShouldBeNil)
// So(user, ShouldEqual, "user")
// })
Convey("cache no exist", func() {
Convey("user exist", func() {
tokenClient.EXPECT().GetUser(gomock.Any(), gomock.Eq(token)).Return("user", nil)
Expand Down

0 comments on commit 3d65f2d

Please sign in to comment.