Commit 2e47495e authored by Ajit Jagtap's avatar Ajit Jagtap
Browse files

Merge branch 'ab_Add_SMGetExt' into 'devbranch'

Add: RetrieveAndExtend to session manager

Closes MKCLOS/coreosv3/corestudio#446

See merge request !195
parents 4e9cc252 9c25cfa0
2 merge requests!197Mep release 15052020,!195Add: RetrieveAndExtend to session manager
Showing with 34 additions and 0 deletions
......@@ -122,6 +122,40 @@ func Retrieve(key string) (Entry, error) {
}
}
// RetrieveAndExtend returns the entry and extends the entry expiration by provided `SECONDS`, only if remaining time < extendBy.
// If extendBy < 0, it is same as Retrieve function.
func RetrieveAndExtend(key string, extendBy int64) (Entry, error) {
entry, err := Retrieve(key)
if err != nil {
return Entry{}, err
}
if extendBy > 0 {
timeRemaining := entry.ExpiredAT - time.Now().Unix()
if timeRemaining < extendBy {
// update with new expiratin
entry.ExpiredAT = time.Now().Add(time.Second * time.Duration(extendBy)).Unix()
Store(key, entry)
}
}
return entry, nil
}
// RetrieveAndDelete deletes the entry after first retrieval
func RetrieveAndDelete(key string) (Entry, error) {
entry, err := Retrieve(key)
if err != nil {
return Entry{}, err
}
store.Delete(key)
return entry, nil
}
// Delete removes the entry from session manager. If the key is not present, error `ErrSessionNotFound` will be thrown. Caller can ignore error if this is acceptable.
func Delete(key string) error {
_, ok := store.Get(key)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment