-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache access tokens client side #3565
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,16 +85,31 @@ func (s SessionStoreImpl[T]) Get(key string, target interface{}) error { | |
return json.Unmarshal([]byte(val), target) | ||
} | ||
|
||
func (s SessionStoreImpl[T]) Put(key string, value interface{}) error { | ||
func (s SessionStoreImpl[T]) Put(key string, value interface{}, options ...SessionOption) error { | ||
opts := s.defaultOptions() | ||
for _, opt := range options { | ||
opt(&opts) | ||
} | ||
// TTL can't go below 0 because that is translated to "no expiration" by the library | ||
// in that case it should be 1 nanosecond | ||
if opts.ttl < 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or just not put it in cache? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤦 |
||
opts.ttl = 1 | ||
} | ||
bytes, err := json.Marshal(value) | ||
if err != nil { | ||
return err | ||
} | ||
return s.underlying.Set(context.Background(), s.db.getFullKey(s.prefixes, key), T(bytes), store.WithExpiration(s.ttl)) | ||
return s.underlying.Set(context.Background(), s.db.getFullKey(s.prefixes, key), T(bytes), store.WithExpiration(opts.ttl)) | ||
} | ||
func (s SessionStoreImpl[T]) GetAndDelete(key string, target interface{}) error { | ||
if err := s.Get(key, target); err != nil { | ||
return err | ||
} | ||
return s.underlying.Delete(context.Background(), s.db.getFullKey(s.prefixes, key)) | ||
} | ||
|
||
func (s SessionStoreImpl[T]) defaultOptions() sessionOptions { | ||
return sessionOptions{ | ||
ttl: s.ttl, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when could it not be set 🤔 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a pointer, probably because the spec says it's optional. In our implementation it's not but you never know.