Documentation ¶
Overview ¶
session implements a simple memory-based session container. version: 1.1.0
NOTE: Suggestion is the number of cached elements should not exceed 100,000, because a large number of elements to runtime.GC() is a burden. More than 100,000 can consider memcache, redis ...
Index ¶
- Variables
- type Storage
- func (storage *Storage) Add(key string, value interface{}) (err error)
- func (storage *Storage) Delete(key string) (err error)
- func (storage *Storage) Get(key string) (value interface{}, err error)
- func (storage *Storage) Len() (n int)
- func (storage *Storage) Set(key string, value interface{}) (err error)
- func (storage *Storage) SetGCInterval(gcInterval int)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = errors.New("item not found") ErrNotStored = errors.New("item not stored") )
Functions ¶
This section is empty.
Types ¶
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
NOTE: Storage is safe for concurrent use by multiple goroutines.
func New ¶
New returns an initialized Storage.
maxAge: seconds, the max age of item in Storage; the maximum is 60 years, and can not be adjusted. gcInterval: seconds, GC interval; the minimal is 1 second.
func (*Storage) Add ¶
Add key-value to Storage. if there already exists a item with the same key, it returns ErrNotStored.
func (*Storage) Delete ¶
Delete the element with key. if there is no such element with the key or the element with the key expired it returns ErrNotFound, normally you can ignore this error.
func (*Storage) Get ¶
Get the element with key. if there is no such element with the key or the element with the key expired it returns ErrNotFound.
func (*Storage) SetGCInterval ¶
Set the NEW gc interval of Storage, seconds.
NOTE: if gcInterval <= 0, we do nothing; after calling this method we will soon do a gc(), please avoid business peak.
Click to show internal directories.
Click to hide internal directories.