mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
Former-commit-id: 4324e81ea94ef917ce39005b6038a6819bb63258
This commit is contained in:
@@ -4,9 +4,14 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/core/errors"
|
||||
"github.com/kataras/iris/core/memstore"
|
||||
)
|
||||
|
||||
// ErrNotImplemented is returned when a particular feature is not yet implemented yet.
|
||||
// It can be matched directly, i.e: `isNotImplementedError := sessions.ErrNotImplemented.Equal(err)`.
|
||||
var ErrNotImplemented = errors.New("not implemented yet")
|
||||
|
||||
// Database is the interface which all session databases should implement
|
||||
// By design it doesn't support any type of cookie session like other frameworks.
|
||||
// I want to protect you, believe me.
|
||||
@@ -20,6 +25,16 @@ type Database interface {
|
||||
// Acquire receives a session's lifetime from the database,
|
||||
// if the return value is LifeTime{} then the session manager sets the life time based on the expiration duration lives in configuration.
|
||||
Acquire(sid string, expires time.Duration) LifeTime
|
||||
// OnUpdateExpiration should re-set the expiration (ttl) of the session entry inside the database,
|
||||
// it is fired on `ShiftExpiration` and `UpdateExpiration`.
|
||||
// If the database does not support change of ttl then the session entry will be cloned to another one
|
||||
// and the old one will be removed, it depends on the chosen database storage.
|
||||
//
|
||||
// Check of error is required, if error returned then the rest session's keys are not proceed.
|
||||
//
|
||||
// Currently only "redis" database is designed to use that event.
|
||||
// If A database is not support this feature then a `ErrNotImplemented` will be returned instead.
|
||||
OnUpdateExpiration(sid string, newExpires time.Duration) error
|
||||
// Set sets a key value of a specific session.
|
||||
// The "immutable" input argument depends on the store, it may not implement it at all.
|
||||
Set(sid string, lifetime LifeTime, key string, value interface{}, immutable bool)
|
||||
@@ -54,6 +69,9 @@ func (s *mem) Acquire(sid string, expires time.Duration) LifeTime {
|
||||
return LifeTime{}
|
||||
}
|
||||
|
||||
// Do nothing, the `LifeTime` of the Session will be managed by the callers automatically on memory-based storage.
|
||||
func (s *mem) OnUpdateExpiration(string, time.Duration) error { return nil }
|
||||
|
||||
// immutable depends on the store, it may not implement it at all.
|
||||
func (s *mem) Set(sid string, lifetime LifeTime, key string, value interface{}, immutable bool) {
|
||||
s.mu.RLock()
|
||||
|
||||
Reference in New Issue
Block a user