mirror of
https://github.com/kataras/iris.git
synced 2026-01-24 04:15:56 +00:00
improve cache handler, embracing #2210 too
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12/context"
|
||||
"github.com/kataras/iris/v12/core/memstore"
|
||||
"github.com/kataras/iris/v12/sessions"
|
||||
|
||||
"github.com/dgraph-io/badger/v2"
|
||||
@@ -82,7 +83,7 @@ func (db *Database) SetLogger(logger *golog.Logger) {
|
||||
|
||||
// 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.
|
||||
func (db *Database) Acquire(sid string, expires time.Duration) sessions.LifeTime {
|
||||
func (db *Database) Acquire(sid string, expires time.Duration) memstore.LifeTime {
|
||||
txn := db.Service.NewTransaction(true)
|
||||
defer txn.Commit()
|
||||
|
||||
@@ -90,7 +91,7 @@ func (db *Database) Acquire(sid string, expires time.Duration) sessions.LifeTime
|
||||
item, err := txn.Get(bsid)
|
||||
if err == nil {
|
||||
// found, return the expiration.
|
||||
return sessions.LifeTime{Time: time.Unix(int64(item.ExpiresAt()), 0)}
|
||||
return memstore.LifeTime{Time: time.Unix(int64(item.ExpiresAt()), 0)}
|
||||
}
|
||||
|
||||
// not found, create an entry with ttl and return an empty lifetime, session manager will do its job.
|
||||
@@ -105,7 +106,7 @@ func (db *Database) Acquire(sid string, expires time.Duration) sessions.LifeTime
|
||||
db.logger.Error(err)
|
||||
}
|
||||
|
||||
return sessions.LifeTime{} // session manager will handle the rest.
|
||||
return memstore.LifeTime{} // session manager will handle the rest.
|
||||
}
|
||||
|
||||
// OnUpdateExpiration not implemented here, yet.
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12/core/memstore"
|
||||
"github.com/kataras/iris/v12/sessions"
|
||||
|
||||
"github.com/kataras/golog"
|
||||
@@ -159,7 +160,7 @@ var expirationKey = []byte("exp") // it can be random.
|
||||
|
||||
// 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.
|
||||
func (db *Database) Acquire(sid string, expires time.Duration) (lifetime sessions.LifeTime) {
|
||||
func (db *Database) Acquire(sid string, expires time.Duration) (lifetime memstore.LifeTime) {
|
||||
bsid := []byte(sid)
|
||||
err := db.Service.Update(func(tx *bolt.Tx) (err error) {
|
||||
root := db.getBucket(tx)
|
||||
@@ -204,7 +205,7 @@ func (db *Database) Acquire(sid string, expires time.Duration) (lifetime session
|
||||
return
|
||||
}
|
||||
|
||||
lifetime = sessions.LifeTime{Time: expirationTime}
|
||||
lifetime = memstore.LifeTime{Time: expirationTime}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -214,7 +215,7 @@ func (db *Database) Acquire(sid string, expires time.Duration) (lifetime session
|
||||
})
|
||||
if err != nil {
|
||||
db.logger.Debugf("unable to acquire session '%s': %v", sid, err)
|
||||
return sessions.LifeTime{}
|
||||
return memstore.LifeTime{}
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12/core/memstore"
|
||||
"github.com/kataras/iris/v12/sessions"
|
||||
|
||||
"github.com/kataras/golog"
|
||||
@@ -138,7 +139,7 @@ const SessionIDKey = "session_id"
|
||||
|
||||
// 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.
|
||||
func (db *Database) Acquire(sid string, expires time.Duration) sessions.LifeTime {
|
||||
func (db *Database) Acquire(sid string, expires time.Duration) memstore.LifeTime {
|
||||
sidKey := db.makeSID(sid)
|
||||
if !db.c.Driver.Exists(sidKey) {
|
||||
if err := db.Set(sid, SessionIDKey, sid, 0, false); err != nil {
|
||||
@@ -149,11 +150,11 @@ func (db *Database) Acquire(sid string, expires time.Duration) sessions.LifeTime
|
||||
}
|
||||
}
|
||||
|
||||
return sessions.LifeTime{} // session manager will handle the rest.
|
||||
return memstore.LifeTime{} // session manager will handle the rest.
|
||||
}
|
||||
|
||||
untilExpire := db.c.Driver.TTL(sidKey)
|
||||
return sessions.LifeTime{Time: time.Now().Add(untilExpire)}
|
||||
return memstore.LifeTime{Time: time.Now().Add(untilExpire)}
|
||||
}
|
||||
|
||||
// OnUpdateExpiration will re-set the database's session's entry ttl.
|
||||
|
||||
Reference in New Issue
Block a user