memory

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: MIT Imports: 3 Imported by: 0

README

gFly Session - Memory

Usage

Install

go get -u github.com/gflydev/session@v1.0.1
go get -u github.com/gflydev/session/memory@v1.0.1

Quick usage main.go

import (
    "github.com/gflydev/session"
    sessionMemory "github.com/gflydev/session/memory"	
)

// Setup session
session.Register(sessionMemory.New())
core.RegisterSession(session.New())
Controller (Page/API)
// Set session
c.SetSession("foo", utils.UnsafeStr(utils.RandByte(make([]byte, 128))))

// Get session parameter `foo`
foo := c.GetSession("foo")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct{}

Config provider settings

type Provider

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

Provider backend manager

func New

func New() *Provider

New returns a new memory provider configured

func (*Provider) Count

func (p *Provider) Count() (count int)

Count returns the total of stored sessions

func (*Provider) Destroy

func (p *Provider) Destroy(id []byte) error

Destroy destroys the session from the given id

func (*Provider) GC

func (p *Provider) GC() error

GC destroys the expired sessions

func (*Provider) Get

func (p *Provider) Get(id []byte) ([]byte, error)

Get returns the data of the given session id

func (*Provider) NeedGC

func (p *Provider) NeedGC() bool

NeedGC indicates if the GC needs to be run

func (*Provider) Regenerate

func (p *Provider) Regenerate(id, newID []byte, expiration time.Duration) error

Regenerate updates the session id and expiration with the new session id of the the given current session id

func (*Provider) Save

func (p *Provider) Save(id, data []byte, expiration time.Duration) error

Save saves the session data and expiration from the given session id

Jump to

Keyboard shortcuts

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