xorm: xorm.io/xorm/caches Index | Files

package caches

import "xorm.io/xorm/caches"

Index

Package Files

cache.go encode.go leveldb.go lru.go manager.go memory_store.go

Constants

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

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

func Decode Uses

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

func Encode Uses

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

func GenSqlKey Uses

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

GenSqlKey generates cache key

func GetCacheSql Uses

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

GetCacheSql returns cacher PKs via SQL

func GobDecode Uses

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

func GobEncode Uses

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

func JsonDecode Uses

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

func JsonEncode Uses

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

func Md5 Uses

func Md5(str string) string

md5 hash string

func PutCacheSql Uses

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

PutCacheSql puts cacher SQL and PKs

type CacheStore Uses

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 Uses

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 Uses

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

LRUCacher implments cache object facilities

func NewLRUCacher Uses

func NewLRUCacher(store CacheStore, maxElementSize int) *LRUCacher

NewLRUCacher creates a cacher

func NewLRUCacher2 Uses

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

NewLRUCacher2 creates a cache include different params

func (*LRUCacher) ClearBeans Uses

func (m *LRUCacher) ClearBeans(tableName string)

ClearBeans clears all beans in some table

func (*LRUCacher) ClearIds Uses

func (m *LRUCacher) ClearIds(tableName string)

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

func (*LRUCacher) DelBean Uses

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

DelBean deletes beans in some table

func (*LRUCacher) DelIds Uses

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

DelIds deletes ids

func (*LRUCacher) GC Uses

func (m *LRUCacher) GC()

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

func (*LRUCacher) GetBean Uses

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

GetBean returns bean according tableName and id from cache

func (*LRUCacher) GetIds Uses

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

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

func (*LRUCacher) PutBean Uses

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

PutBean puts beans into table

func (*LRUCacher) PutIds Uses

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

PutIds pus ids into table

func (*LRUCacher) RunGC Uses

func (m *LRUCacher) RunGC()

RunGC run once every m.GcInterval

type LevelDBStore Uses

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

LevelDBStore implements CacheStore provide local machine

func NewLevelDBStore Uses

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

func (*LevelDBStore) Close Uses

func (s *LevelDBStore) Close()

func (*LevelDBStore) Del Uses

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

func (*LevelDBStore) Get Uses

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

func (*LevelDBStore) Put Uses

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

type Manager Uses

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

func NewManager Uses

func NewManager() *Manager

func (*Manager) GetCacher Uses

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

func (*Manager) GetDefaultCacher Uses

func (mgr *Manager) GetDefaultCacher() Cacher

GetDefaultCacher returns the default cacher

func (*Manager) SetCacher Uses

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

func (*Manager) SetDefaultCacher Uses

func (mgr *Manager) SetDefaultCacher(cacher Cacher)

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

func (*Manager) SetDisableGlobalCache Uses

func (mgr *Manager) SetDisableGlobalCache(disable bool)

SetDisableGlobalCache disable global cache or not

type MemoryStore Uses

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

MemoryStore represents in-memory store

func NewMemoryStore Uses

func NewMemoryStore() *MemoryStore

NewMemoryStore creates a new store in memory

func (*MemoryStore) Del Uses

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

Del deletes object

func (*MemoryStore) Get Uses

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

Get gets object from store

func (*MemoryStore) Put Uses

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

Put puts object into store

Package caches imports 14 packages (graph) and is imported by 7 packages. Updated 2020-06-18. Refresh now. Tools for package owners.