Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ICache ¶
type ICache interface { // Get 从本地内存中获取 Get() collections.ListAny // GetItem 获取集合中的item GetItem(cacheId any) any // GetItems 获取集合中多个的item GetItems(cacheIds []any) collections.ListAny // Set 整个数据保存到缓存(失效时间只在这里调用后,才会生效) Set(val collections.ListAny) // SaveItem 添加或修改集合的Item SaveItem(newVal any) // Remove 移除缓存 Remove(cacheId any) // Clear 清空缓存 Clear() // Count 获取集合数量 Count() int // ExistsItem 指定数据是否存在 ExistsItem(cacheId any) bool // ExistsKey 缓存是否存在 ExistsKey() bool // GetUniqueId 获取唯一字段数据 GetUniqueId(item any) string }
ICache 缓存操作
type ICacheManage ¶ added in v0.2.0
type ICacheManage[TEntity any] interface { // SetListSource 集合数据不存在时,则通过getListSourceFn获取 SetListSource(getListSourceFn func() collections.List[TEntity]) // SetItemSource 元素不存在时,则通过getItemSourceFn获取 SetItemSource(getItemSourceFn func(cacheId any) (TEntity, bool)) // EnableItemNullToLoadAll 元素不存在时,自动读取集合数据源 EnableItemNullToLoadAll() // Get 获取缓存数据 Get() collections.List[TEntity] // Single 获取单个对象 Single() TEntity // GetItem 从集合中获取指定cacheId的元素 GetItem(cacheId any) (TEntity, bool) // GetItems 从集合中获取多个cacheId的元素 GetItems(cacheIds ...any) collections.List[TEntity] // Set 缓存整个集合,将覆盖原有集合(如果有数据) Set(val ...TEntity) // SaveItem 更新item数据到集合 SaveItem(newVal TEntity) // Remove 移除集合中的item数据 Remove(cacheId any) // Clear 清空数据 Clear() // ExistsKey 缓存集合是否存在:如果没初始过Key,或者Key缓存已失效,都会返回false ExistsKey() bool // ExistsItem 缓存是否存在 ExistsItem(cacheId any) bool // Count 获取集合内的数量 Count() int // SetSyncSource 设置定义将缓存的数据同步到你需要的位置,比如同步到数据库 SetSyncSource(duration time.Duration, f func(val TEntity)) // SetClearSource 设置定义清理缓存中的数据 SetClearSource(duration time.Duration, f func(val TEntity) bool) }
func RegisterCacheModule ¶ added in v0.2.0
func RegisterCacheModule[TEntity any](key string, cacheStoreType string, uniqueField string, cache ICache) ICacheManage[TEntity]
RegisterCacheModule 注册缓存
type Module ¶
type Module struct { }
func (Module) DependsModule ¶
func (module Module) DependsModule() []modules.FarseerModule
type Op ¶ added in v0.8.0
type Op struct { ExpiryType eumExpiryType.Enum // 过期策略 Expiry time.Duration // 缓存失效时间 }
Op 缓存选项
func (*Op) AbsoluteExpiration ¶ added in v0.8.0
AbsoluteExpiration 绝对时间,到期自动移除
func (*Op) SlidingExpiration ¶ added in v0.8.0
SlidingExpiration 任意一次访问都会重置过期时间
Source Files
¶
Click to show internal directories.
Click to hide internal directories.