import "xorm.io/xorm/caches"
cache.go encode.go leveldb.go lru.go manager.go memory_store.go
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 )
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
GenSqlKey generates cache key
GetCacheSql returns cacher PKs via SQL
md5 hash string
PutCacheSql puts cacher SQL and PKs
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 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 struct { MaxElementSize int Expired time.Duration GcInterval time.Duration // contains filtered or unexported fields }
LRUCacher implments cache object facilities
func NewLRUCacher(store CacheStore, maxElementSize int) *LRUCacher
NewLRUCacher creates a cacher
NewLRUCacher2 creates a cache include different params
ClearBeans clears all beans in some table
ClearIds clears all sql-ids mapping on table tableName from cache
DelBean deletes beans in some table
DelIds deletes ids
GC check ids lit and sql list to remove all element expired
GetBean returns bean according tableName and id from cache
GetIds returns all bean's ids according to sql and parameter from cache
PutBean puts beans into table
PutIds pus ids into table
RunGC run once every m.GcInterval
LevelDBStore implements CacheStore provide local machine
func NewLevelDBStore(dbfile string) (*LevelDBStore, error)
func (s *LevelDBStore) Close()
func (s *LevelDBStore) Del(key string) error
func (s *LevelDBStore) Get(key string) (interface{}, error)
func (s *LevelDBStore) Put(key string, value interface{}) error
type Manager struct {
// contains filtered or unexported fields
}
GetDefaultCacher returns the default cacher
SetDefaultCacher set the default cacher. Xorm's default not enable cacher.
SetDisableGlobalCache disable global cache or not
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore represents in-memory store
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new store in memory
func (s *MemoryStore) Del(key string) error
Del deletes object
func (s *MemoryStore) Get(key string) (interface{}, error)
Get gets object from store
func (s *MemoryStore) Put(key string, value interface{}) error
Put puts object into store
Package caches imports 14 packages (graph) and is imported by 9 packages. Updated 2021-01-21. Refresh now. Tools for package owners.