sessionmanagermdl

package
v2.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// keys for the entry object
	KEY_DATA       = "data"
	KEY_EXPIREDAT  = "expiredAt"
	KEY_EXPIRATION = "expiration"
)

Variables

View Source
var ErrInvalidDataType = errors.New("INVALID_DATA_Type")
View Source
var ErrSessionNotFound = errors.New("SESSION_NOT_FOUND")

Functions

func Delete

func Delete(key string) error

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 Init

func Init(cache cachemdl.Cacher)

Init initializes session manager with provided cache. Subsequent calls will not have any effect after first initialization.

func NewRedisEntry

func NewRedisEntry(entry Entry) string

NewRedisEntry prepares the entry for redis cache. This is required because redis accepts a byte array.

func RetrieveAll

func RetrieveAll() map[string]interface{}

RetrieveAll returns all entries present in memory. **Not for production use. May add performance costs**

func Store

func Store(key string, entry Entry)

Store adds/ updates the entry against the provided key.

func ToObject

func ToObject(entry Entry) map[string]interface{}

ToObject returns an cache entry as an object. It is better than sjson.Set() as we need to perform gjson.Parse().

Types

type Entry

type Entry struct {
	Data       gjson.Result `json:"data,omitempty"`
	Expiration int64        `json:"expiration,omitempty"`
	ExpiredAT  int64        `json:"expiredAt,omitempty"`
}

Entry is a data to be stored against a key.

func NewEntry

func NewEntry(val gjson.Result, exp int64) Entry

NewEntry prepares the object required to store data in session.

The `exp` field interprets time in seconds. Ex. For 5 seconds, set `5`

func Retrieve

func Retrieve(key string) (Entry, error)

Retrieve returns the entry present against the provided key. If a key is not available or data stored is not of type gjson.Result, a non nil error will be returned

func RetrieveAndDelete

func RetrieveAndDelete(key string) (Entry, error)

RetrieveAndDelete deletes the entry after first retrieval

func RetrieveAndExtend

func RetrieveAndExtend(key string, extendBy int64) (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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL