caches

package
v1.2.10 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CacheExpired is default cache expired time
	CacheExpired = 60 * time.Minute
	// CacheMaxMemory is not use now
	CacheMaxMemory = 256
	// CacheGcInterval represents interval time to clear all expired nodes
	CacheGcInterval = 10 * time.Minute
	// CacheGcMaxRemoved represents max nodes removed when gc
	CacheGcMaxRemoved = 20
)

Variables

View Source
var (
	ErrCacheMiss = errors.New("xorm/cache: key not found")
	ErrNotStored = errors.New("xorm/cache: not stored")
	// ErrNotExist record does not exist error
	ErrNotExist = errors.New("Record does not exist")
)

list all the errors

Functions

func Decode

func Decode(data []byte, to interface{}) error

func Encode

func Encode(data interface{}) ([]byte, error)

func GenSqlKey

func GenSqlKey(sql string, args interface{}) string

GenSqlKey generates cache key

func GetCacheSql

func GetCacheSql(m Cacher, tableName, sql string, args interface{}) ([]schemas.PK, error)

GetCacheSql returns cacher PKs via SQL

func GobDecode

func GobDecode(data []byte, to interface{}) error

func GobEncode

func GobEncode(data interface{}) ([]byte, error)

func JsonDecode

func JsonDecode(data []byte, to interface{}) error

func JsonEncode

func JsonEncode(data interface{}) ([]byte, error)

func Md5

func Md5(str string) string

md5 hash string

func PutCacheSql

func PutCacheSql(m Cacher, ids []schemas.PK, tableName, sql string, args interface{}) error

PutCacheSql puts cacher SQL and PKs

Types

type CacheStore

type CacheStore interface {
	// key is primary key or composite primary key
	// value is struct's pointer
	// key format : <tablename>-p-<pk1>-<pk2>...
	Put(key string, value interface{}) error
	Get(key string) (interface{}, error)
	Del(key string) error
}

CacheStore is a interface to store cache

type Cacher

type Cacher interface {
	GetIds(tableName, sql string) interface{}
	GetBean(tableName string, id string) interface{}
	PutIds(tableName, sql string, ids interface{})
	PutBean(tableName string, id string, obj interface{})
	DelIds(tableName, sql string)
	DelBean(tableName string, id string)
	ClearIds(tableName string)
	ClearBeans(tableName string)
}

Cacher is an interface to provide cache id format : u-<pk1>-<pk2>...

type LRUCacher

type LRUCacher struct {
	MaxElementSize int
	Expired        time.Duration
	GcInterval     time.Duration
	// contains filtered or unexported fields
}

LRUCacher implments cache object facilities

func NewLRUCacher

func NewLRUCacher(store CacheStore, maxElementSize int) *LRUCacher

NewLRUCacher creates a cacher

func NewLRUCacher2

func NewLRUCacher2(store CacheStore, expired time.Duration, maxElementSize int) *LRUCacher

NewLRUCacher2 creates a cache include different params

func (*LRUCacher) ClearBeans

func (m *LRUCacher) ClearBeans(tableName string)

ClearBeans clears all beans in some table

func (*LRUCacher) ClearIds

func (m *LRUCacher) ClearIds(tableName string)

ClearIds clears all sql-ids mapping on table tableName from cache

func (*LRUCacher) DelBean

func (m *LRUCacher) DelBean(tableName string, id string)

DelBean deletes beans in some table

func (*LRUCacher) DelIds

func (m *LRUCacher) DelIds(tableName, sql string)

DelIds deletes ids

func (*LRUCacher) GC

func (m *LRUCacher) GC()

GC check ids lit and sql list to remove all element expired

func (*LRUCacher) GetBean

func (m *LRUCacher) GetBean(tableName string, id string) interface{}

GetBean returns bean according tableName and id from cache

func (*LRUCacher) GetIds

func (m *LRUCacher) GetIds(tableName, sql string) interface{}

GetIds returns all bean's ids according to sql and parameter from cache

func (*LRUCacher) PutBean

func (m *LRUCacher) PutBean(tableName string, id string, obj interface{})

PutBean puts beans into table

func (*LRUCacher) PutIds

func (m *LRUCacher) PutIds(tableName, sql string, ids interface{})

PutIds pus ids into table

func (*LRUCacher) RunGC

func (m *LRUCacher) RunGC()

RunGC run once every m.GcInterval

type LevelDBStore

type LevelDBStore struct {
	Debug bool
	// contains filtered or unexported fields
}

LevelDBStore implements CacheStore provide local machine

func NewLevelDBStore

func NewLevelDBStore(dbfile string) (*LevelDBStore, error)

func (*LevelDBStore) Close

func (s *LevelDBStore) Close()

func (*LevelDBStore) Del

func (s *LevelDBStore) Del(key string) error

func (*LevelDBStore) Get

func (s *LevelDBStore) Get(key string) (interface{}, error)

func (*LevelDBStore) Put

func (s *LevelDBStore) Put(key string, value interface{}) error

type Manager

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

func NewManager

func NewManager() *Manager

func (*Manager) GetCacher

func (mgr *Manager) GetCacher(tableName string) Cacher

func (*Manager) GetDefaultCacher

func (mgr *Manager) GetDefaultCacher() Cacher

GetDefaultCacher returns the default cacher

func (*Manager) SetCacher

func (mgr *Manager) SetCacher(tableName string, cacher Cacher)

func (*Manager) SetDefaultCacher

func (mgr *Manager) SetDefaultCacher(cacher Cacher)

SetDefaultCacher set the default cacher. Xorm's default not enable cacher.

func (*Manager) SetDisableGlobalCache

func (mgr *Manager) SetDisableGlobalCache(disable bool)

SetDisableGlobalCache disable global cache or not

type MemoryStore

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

MemoryStore represents in-memory store

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates a new store in memory

func (*MemoryStore) Del

func (s *MemoryStore) Del(key string) error

Del deletes object

func (*MemoryStore) Get

func (s *MemoryStore) Get(key string) (interface{}, error)

Get gets object from store

func (*MemoryStore) Put

func (s *MemoryStore) Put(key string, value interface{}) error

Put puts object into store

Jump to

Keyboard shortcuts

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