Documentation ¶
Index ¶
- Constants
- Variables
- func Decode(data []byte, to interface{}) error
- func Encode(data interface{}) ([]byte, error)
- func GenSqlKey(sql string, args interface{}) string
- func GetCacheSql(m Cacher, tableName, sql string, args interface{}) ([]schemas.PK, error)
- func GobDecode(data []byte, to interface{}) error
- func GobEncode(data interface{}) ([]byte, error)
- func JsonDecode(data []byte, to interface{}) error
- func JsonEncode(data interface{}) ([]byte, error)
- func Md5(str string) string
- func PutCacheSql(m Cacher, ids []schemas.PK, tableName, sql string, args interface{}) error
- type CacheStore
- type Cacher
- type LRUCacher
- func (m *LRUCacher) ClearBeans(tableName string)
- func (m *LRUCacher) ClearIds(tableName string)
- func (m *LRUCacher) DelBean(tableName string, id string)
- func (m *LRUCacher) DelIds(tableName, sql string)
- func (m *LRUCacher) GC()
- func (m *LRUCacher) GetBean(tableName string, id string) interface{}
- func (m *LRUCacher) GetIds(tableName, sql string) interface{}
- func (m *LRUCacher) PutBean(tableName string, id string, obj interface{})
- func (m *LRUCacher) PutIds(tableName, sql string, ids interface{})
- 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
func JsonDecode ¶
JsonDecode decode data with json
func JsonEncode ¶
JsonEncode encode data with json
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 ¶
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
func (*LevelDBStore) Get ¶
func (s *LevelDBStore) Get(key string) (interface{}, error)
Get implements CacheStore
func (*LevelDBStore) Put ¶
func (s *LevelDBStore) Put(key string, value interface{}) error
Put implements CacheStore
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
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