Documentation
¶
Index ¶
- Constants
- Variables
- func Decode(data []byte, to any) error
- func Encode(data any) ([]byte, error)
- func GenSqlKey(sql string, args any) string
- func GetCacheSql(m Cacher, tableName, sql string, args any) ([]schemas.PK, error)
- func GobDecode(data []byte, to any) error
- func GobEncode(data any) ([]byte, error)
- func JsonDecode(data []byte, to any) error
- func JsonEncode(data any) ([]byte, error)
- func Md5(str string) string
- func PutCacheSql(m Cacher, ids []schemas.PK, tableName, sql string, args any) error
- type CacheStore
- type Cacher
- type LRUCacher
- func (m *LRUCacher) ClearBeans(tableName string)
- func (m *LRUCacher) ClearIds(tableName string)
- func (m *LRUCacher) DelBean(tableName, id string)
- func (m *LRUCacher) DelIds(tableName, sql string)
- func (m *LRUCacher) GC()
- func (m *LRUCacher) GetBean(tableName, id string) any
- func (m *LRUCacher) GetIds(tableName, sql string) any
- func (m *LRUCacher) PutBean(tableName, id string, obj any)
- func (m *LRUCacher) PutIds(tableName, sql string, ids any)
- func (m *LRUCacher) RunGC()
- type LevelDBStore
- type Manager
- type MemoryStore
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
Functions ¶
func GetCacheSql ¶
GetCacheSql returns cacher PKs via SQL
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 any) error
Get(key string) (any, error)
Del(key string) error
}
CacheStore is a interface to store cache
type Cacher ¶
type Cacher interface {
GetIds(tableName, sql string) any
GetBean(tableName, id string) any
PutIds(tableName, sql string, ids any)
PutBean(tableName, id string, obj any)
DelIds(tableName, sql string)
DelBean(tableName, 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 ¶
ClearBeans clears all beans in some table
func (*LRUCacher) GC ¶
func (m *LRUCacher) GC()
GC check ids lit and sql list to remove all element expired
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)
NewLevelDBStore creates a leveldb store
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager represents a cache manager
func (*Manager) GetDefaultCacher ¶
GetDefaultCacher returns the default cacher
func (*Manager) SetDefaultCacher ¶
SetDefaultCacher set the default cacher. Xorm's default not enable cacher.
func (*Manager) SetDisableGlobalCache ¶
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