Documentation
¶
Overview ¶
Package cache ============================================================================= # Author: peng.wei # Email: [email protected] # Version: 0.0.1 # LastChange: 20211214 # History: =============================================================================
Package cache ============================================================================= # Author: peng.wei # Email: [email protected] # Version: 0.0.1 # LastChange: 20211214 # History: =============================================================================
Package cache ============================================================================= # Author: peng.wei # Email: [email protected] # Version: 0.0.1 # LastChange: 20211214 # History: =============================================================================
Package cache ============================================================================= # Author: peng.wei # Email: [email protected] # Version: 0.0.1 # LastChange: 20211214 # History: =============================================================================
Index ¶
- Variables
- func IndexGet[T any](i Indexed) (rx T, ok bool)
- func PowerSet[T any](s []T) [][]T
- type Cache
- func (c *Cache[K, V]) Clean()
- func (c *Cache[K, V]) Clear()
- func (c *Cache[K, V]) Del(k K)
- func (c *Cache[K, V]) Get(req K) (V, bool)
- func (c *Cache[K, V]) Has(k ...K) bool
- func (c *Cache[K, V]) HasAny(k ...K) bool
- func (c *Cache[K, V]) IsEmpty() bool
- func (c *Cache[K, V]) Len() int
- func (c *Cache[K, V]) List() ([]K, []V)
- func (c *Cache[K, V]) ListKey() []K
- func (c *Cache[K, V]) ListValue() []V
- func (c *Cache[K, V]) Merge(s *Cache[K, V])
- func (c *Cache[K, V]) Name() string
- func (c *Cache[K, V]) Options() []Option[K, V]
- func (c *Cache[K, V]) Range(fn func(k K, v V) bool)
- func (c *Cache[K, V]) Remove(k ...K)
- func (c *Cache[K, V]) Set(req K, values V)
- func (c *Cache[K, V]) Size() int
- type CacheI
- type CacheManager
- type IndexFunc
- type Indexed
- type Indexer
- func (ix *Indexer[T]) Add(v ...T)
- func (ix *Indexer[T]) Clear()
- func (ix *Indexer[T]) Del(v interface{})
- func (ix *Indexer[T]) Get(id string) (v T, ok bool)
- func (ix *Indexer[T]) Has(v ...T) bool
- func (ix *Indexer[T]) IsEmpty() bool
- func (ix *Indexer[T]) Len() int
- func (ix *Indexer[T]) List() ([]string, []T)
- func (ix *Indexer[T]) ListKey() []string
- func (ix *Indexer[T]) ListValue() []T
- func (ix *Indexer[T]) Merge(s *Indexer[T])
- func (ix *Indexer[T]) Pop() T
- func (ix *Indexer[T]) Range(fn func(k string, v T) bool)
- func (ix *Indexer[T]) Remove(v ...T)
- func (ix *Indexer[T]) Search(idxName string, key string) *SearchResult[T]
- func (ix *Indexer[T]) Set(v T) bool
- func (ix *Indexer[T]) SetFromIndex(idxName string) (*Set[string], error)
- func (ix *Indexer[T]) Size() int
- type InterfaceCache
- type InterfaceIndexer
- type InterfaceSet
- type Option
- type SearchResult
- type Set
- func (s *Set[K]) Add(key ...K)
- func (s *Set[K]) Clear()
- func (s *Set[K]) Copy() *Set[K]
- func (s *Set[K]) Difference(o *Set[K], opts ...Option[K, struct{}]) *Set[K]
- func (s *Set[K]) Get(key K) bool
- func (s *Set[K]) Has(items ...K) bool
- func (s *Set[K]) HasAny(items ...K) bool
- func (s *Set[K]) Intersection(o *Set[K], opts ...Option[K, struct{}]) *Set[K]
- func (s *Set[K]) IsEmpty() bool
- func (s *Set[K]) IsEqual(o *Set[K]) bool
- func (s *Set[K]) IsSubset(o *Set[K]) (subset bool)
- func (s *Set[K]) IsSuperset(o *Set[K]) bool
- func (s *Set[K]) List() []K
- func (s *Set[K]) Merge(o *Set[K])
- func (s *Set[K]) Pop() (res K)
- func (s *Set[K]) PowerSet(key ...K) (powerSet []*Set[K])
- func (s *Set[K]) Range(fn func(k K) bool)
- func (s *Set[K]) Remove(key ...K)
- func (s *Set[K]) Separate(t *Set[K])
- func (s *Set[K]) Size() int
- func (s *Set[K]) Sub(o *Set[K], opts ...Option[K, struct{}]) *Set[K]
- func (s *Set[K]) Union(o *Set[K], opts ...Option[K, struct{}]) *Set[K]
- type TimeValue
- type TimeoutValue
Constants ¶
This section is empty.
Variables ¶
var CacheManagerFactory = func() CacheManager {
return defaultManager
}
CacheManagerFactory 返回 CacheManager 的方法
var ( // Forever 永远不超时 Forever = time.Hour * 24 * 365 * 100 )
Functions ¶
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache 是一个带超时的缓存, 超时的元素会获取不到并删除(默认情况下)
func NewCache ¶
func NewCache[K comparable, V any](opts ...Option[K, V]) *Cache[K, V]
NewCache 创建新cache
func NewCacheInits ¶ added in v1.3.0
func NewCacheInits[K comparable, V any](inits map[K]V, opts ...Option[K, V]) *Cache[K, V]
NewCacheInits 创建新cache
func (*Cache[K, V]) ListKey ¶ added in v1.2.0
func (c *Cache[K, V]) ListKey() []K
ListKey func list k
func (*Cache[K, V]) ListValue ¶ added in v1.2.0
func (c *Cache[K, V]) ListValue() []V
ListValue func list v
type CacheI ¶
type CacheI interface {
Clean()
Name() string
}
CacheI 接口, 一个结构实现了CacheI 接口才可以被CacheManager 使用
type CacheManager ¶
type CacheManager interface {
Tasks() // CacheManager 的tasks 会定期执行
RegisterCache(c CacheI) // 注册cache
Interval() time.Duration // 返回执行tasks的间隔
}
CacheManager 持有所有的cache 可以定时执行cache 的tasks
type Indexer ¶
type Indexer[T Indexed] struct { // contains filtered or unexported fields }
Indexer 是带索引的cache
func NewIndexer ¶
NewIndexer 创建一个带索引的cache
func (*Indexer[T]) ListValue ¶ added in v1.2.0
func (ix *Indexer[T]) ListValue() []T
ListValue func list v
func (*Indexer[T]) Search ¶
func (ix *Indexer[T]) Search(idxName string, key string) *SearchResult[T]
Search 根据索引函数查找Indexer
func (*Indexer[T]) SetFromIndex ¶
SetFromIndex 从indexName 创建一个Set
type InterfaceCache ¶ added in v1.1.2
type InterfaceCache[K comparable, V any] interface { Set(req K, values V) Remove(key ...K) Has(items ...K) bool HasAny(k ...K) bool Size() int Clear() IsEmpty() bool Range(fn func(s string, k K) bool) List() ([]K, []V) ListKey() []K ListValue() []V Merge(s *Cache[K, V]) }
InterfaceCache 是cache的接口
type InterfaceIndexer ¶ added in v1.1.2
type InterfaceIndexer[K Indexed] interface { Add(key ...K) Remove(key ...K) Pop() K Has(items ...K) bool Size() int Clear() IsEmpty() bool Range(fn func(s string, k K) bool) List() ([]string, []K) ListKey() []string ListValue() []K Merge(s *Indexer[K]) }
InterfaceIndexer 是Indexer的接口
type InterfaceSet ¶
type InterfaceSet[K comparable] interface { Add(key ...K) Remove(key ...K) Pop() K Has(items ...K) bool HasAny(k ...K) bool Size() int Clear() IsEmpty() bool IsEqual(s *Set[K]) bool IsSubset(s *Set[K]) bool IsSuperset(s *Set[K]) bool Range(fn func(k K) bool) List() []K Copy() *Set[K] Merge(s *Set[K]) Separate(t *Set[K]) }
InterfaceSet 是set的接口
type Option ¶
type Option[K comparable, V any] func(*Cache[K, V])
Option cache 的选项
func WithNoManager ¶
func WithNoManager[K comparable, V any]() Option[K, V]
WithNoManager 设置cache不受 cacheManager管理
type SearchResult ¶
type SearchResult[T Indexed] struct { Res []T // contains filtered or unexported fields }
SearchResult 是Indexer 根据索引函数查找的结果
type Set ¶
type Set[K comparable] struct { // contains filtered or unexported fields }
Set 是Set 型的cache 会多几个集合操作
func NewSetInits ¶
func NewSetInits[K comparable](inits []K, opts ...Option[K, struct{}]) *Set[K]
NewSetInits 新创建set
func (*Set[K]) Difference ¶
Difference godoc
func (*Set[K]) HasAny ¶ added in v1.5.2
HasAny 检查是否存在任何一个传递的项目。如果未传递任何内容,则返回 false。对于多个项目,只要有一个存在就返回 true。
func (*Set[K]) Intersection ¶
Intersection 交集