scs: github.com/alexedwards/scs/stores/memstore Index | Files

package memstore

import "github.com/alexedwards/scs/stores/memstore"

Package memstore is a in-memory session store for the SCS session package.

Warning: Because memstore uses in-memory storage only, all session data will be lost when your Go program is stopped or restarted. On the upside though, it is blazingly fast.

In production, memstore should only be used where this volatility is an acceptable trade-off for the high performance, and where lost session data will have a negligible impact on users.

The memstore package provides a background 'cleanup' goroutine to delete expired session data. This stops the underlying cache from holding on to invalid sessions forever and taking up unnecessary memory.

Index

Package Files

memstore.go

type MemStore Uses

type MemStore struct {
    // contains filtered or unexported fields
}

MemStore represents the currently configured session session store. It is essentially a wrapper around a go-cache instance (see https://github.com/patrickmn/go-cache).

func New Uses

func New(cleanupInterval time.Duration) *MemStore

New returns a new MemStore instance.

The cleanupInterval parameter controls how frequently expired session data is removed by the background 'cleanup' goroutine. Setting it to 0 prevents the cleanup goroutine from running (i.e. expired sessions will not be removed).

func (*MemStore) Delete Uses

func (m *MemStore) Delete(token string) error

Delete removes a session token and corresponding data from the MemStore instance.

func (*MemStore) Find Uses

func (m *MemStore) Find(token string) (b []byte, exists bool, err error)

Find returns the data for a given session token from the MemStore instance. If the session token is not found or is expired, the returned exists flag will be set to false.

func (*MemStore) Save Uses

func (m *MemStore) Save(token string, b []byte, expiry time.Time) error

Save adds a session token and data to the MemStore instance with the given expiry time. If the session token already exists then the data and expiry time are updated.

Package memstore imports 3 packages (graph) and is imported by 3 packages. Updated 2017-12-15. Refresh now. Tools for package owners.