58 lines
2 KiB
Go
58 lines
2 KiB
Go
package hybrid
|
|
|
|
// Provider interace implement lifecycle for one sessions
|
|
type Provider interface {
|
|
//set additional params for provider ex: sql db connection, filesystem path .. etc.
|
|
SetParams(params any) error
|
|
//create new session using sid value 1) in meory 2) into WAL file create new session op.
|
|
Init(sid string) (Session, error)
|
|
//read and return existing session by id or if not exist create new session 1) from
|
|
//memory WAL file no need modify i no call Init from Load...
|
|
Load(sid string) (Session, error)
|
|
//destroy remove session with sid from storage if exist 1) in memory 2) in WAL ile
|
|
//add destroy operation
|
|
Destroy(sid string) error
|
|
//regenerate id change old sid to newsid and preserve existing session data 1) in memory
|
|
//and 2) add change id op. into WAL file
|
|
ChangeID(oldsid, newsid string) (err error)
|
|
//Exists return true if session with sid exist
|
|
Exists(sid string) bool
|
|
//gc remove all outdated sessions 1) in memory and 2) add every destroy op. into WAL
|
|
GC(maxlifetime int64)
|
|
}
|
|
|
|
// Session interface implement storage for one session and have maxLifetime and lastAccessTime
|
|
/*
|
|
Session change WAL file (SCF) file format:
|
|
|
|
| OP. NUM. | SID | DATA (binary stream) | LEN |
|
|
|
|
OP. NUM. : uint8
|
|
|
|
0 - create new session
|
|
1 - destroy session
|
|
2 - change session ID
|
|
3 - modify (create, update and delete) session key/val data
|
|
|
|
SID:
|
|
- 32 bit. session ID
|
|
|
|
DATA:
|
|
0: --no data--
|
|
1: --no-data--
|
|
2: new SID
|
|
3:
|
|
create: key([]byte)|val([]byte)
|
|
delete: key([]byte)
|
|
update: key([]byte)|val([]byte)
|
|
*/
|
|
type Session interface {
|
|
//set session value and update last access time 1) in memory and 2) add Set key op. into WAL
|
|
Set(key, value any) error
|
|
//get session value and update last access time 1) from memory and no need any WAL modiication
|
|
Get(key any) (v any, err error)
|
|
//delete session value 1) in memory and 2) add delete key op. into WAL
|
|
Delete(key any) error
|
|
//get session id 1) from memory and no need mod. WAL
|
|
SessionID() string
|
|
}
|