Documentation ¶
Index ¶
- Variables
- func Add(key string, value interface{})
- func AddWithAbsoluteExpiration(key string, value interface{}, expiration time.Time)
- func AddWithCacheItem(item CacheItem)
- func AddWithSlidingExpiration(key string, value interface{}, expiration time.Duration)
- func ContainsKey(key string) bool
- func Count() int
- func Get(key string) (value interface{}, ok bool)
- type CacheEntryCreateCallback
- type CacheEntryRemovedCallback
- type CacheEntryRemovedReason
- type CacheEntryUpdateCallback
- type CacheItem
- type MemoryCache
- func (memory *MemoryCache) Add(key string, value interface{})
- func (memory *MemoryCache) AddWithAbsoluteExpiration(key string, value interface{}, expiration time.Time)
- func (memory *MemoryCache) AddWithCacheItem(item CacheItem)
- func (memory *MemoryCache) AddWithSlidingExpiration(key string, value interface{}, expiration time.Duration)
- func (memory *MemoryCache) Clear()
- func (memory *MemoryCache) Close()
- func (memory *MemoryCache) ContainsKey(key string) bool
- func (memory *MemoryCache) Count() int
- func (memory *MemoryCache) Get(key string) (value interface{}, ok bool)
- func (memory *MemoryCache) Remove(key string) (value interface{}, ok bool)
- type MemoryCacheStore
- func (store *MemoryCacheStore) Add(item *CacheItem)
- func (store *MemoryCacheStore) AddWithAbsoluteExpiration(key string, value interface{}, expiration time.Time)
- func (store *MemoryCacheStore) AddWithSlidingExpiration(key string, value interface{}, expiration time.Duration)
- func (store *MemoryCacheStore) Clear()
- func (store *MemoryCacheStore) Close()
- func (store *MemoryCacheStore) ContainsKey(key string) bool
- func (store *MemoryCacheStore) Count() int
- func (store *MemoryCacheStore) GetValue(key string) (value interface{}, ok bool)
- func (store *MemoryCacheStore) Remove(key string) (value interface{}, ok bool)
- type NoSlidingExpiration
- type SlidingExpiration
Constants ¶
This section is empty.
Variables ¶
View Source
var MaxTimeValue = time.Date(9999, 12, 31, 23, 59, 59, 9999999, time.Local)
View Source
var SHARD_COUNT = 32
Functions ¶
func AddWithCacheItem ¶
func AddWithCacheItem(item CacheItem)
func AddWithSlidingExpiration ¶
增加缓存并设置策略
Types ¶
type CacheEntryCreateCallback ¶
当缓存失效后,可以指定重新生成缓存的回调方法
type CacheEntryRemovedCallback ¶
type CacheEntryRemovedCallback func(key string, value interface{}, reason CacheEntryRemovedReason)
定义对某个方法的引用,在从缓存中移除某个缓存项后将调用该方法
type CacheEntryRemovedReason ¶
type CacheEntryRemovedReason int
指定已移除或将要移除某个缓存项的原因
const ( // 主动移除 CacheEntryRemovedReasonRemoved CacheEntryRemovedReason = iota //某个缓存项由于已过期而被移除。 过期可基于绝对过期时间或可调过期时间 CacheEntryRemovedReasonExpired //某个缓存项由于释放缓存中的内存的原因而被移除。 // 当某个缓存实例将超出特定于缓存的内存限制或某个进程或缓存实例将超出整个计算机范围的内存限制时,会发生这种情况 CacheEntryRemovedReasonEvicted //某个缓存项由于相关依赖项(如一个文件或其他缓存项)触发了其逐出操作而被移除 CacheEntryRemovedReasonChangeMonitorChanged //某个缓存项由于特定缓存实现定义的原因而被逐出 CacheEntryRemovedReasonCacheSpecificEviction )
type CacheEntryUpdateCallback ¶
type CacheEntryUpdateCallback func(key string, value interface{}, reason CacheEntryRemovedReason)
定义对某个方法的引用,在即将从缓存中移除某个缓存项时将调用该方法
type CacheItem ¶
type CacheItem struct { sync.RWMutex Key string Value interface{} RemovedCallback CacheEntryRemovedCallback CreateCallback CacheEntryCreateCallback // contains filtered or unexported fields }
func NewCacheItem ¶
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
func NewMemoryCache ¶
func NewMemoryCache(interval time.Duration) *MemoryCache
func (*MemoryCache) Add ¶
func (memory *MemoryCache) Add(key string, value interface{})
func (*MemoryCache) AddWithAbsoluteExpiration ¶
func (memory *MemoryCache) AddWithAbsoluteExpiration(key string, value interface{}, expiration time.Time)
func (*MemoryCache) AddWithCacheItem ¶
func (memory *MemoryCache) AddWithCacheItem(item CacheItem)
func (*MemoryCache) AddWithSlidingExpiration ¶
func (memory *MemoryCache) AddWithSlidingExpiration(key string, value interface{}, expiration time.Duration)
增加缓存并设置策略
func (*MemoryCache) Clear ¶
func (memory *MemoryCache) Clear()
func (*MemoryCache) Close ¶
func (memory *MemoryCache) Close()
func (*MemoryCache) ContainsKey ¶
func (memory *MemoryCache) ContainsKey(key string) bool
ContainsKey 判断缓存中是否存在指定键
func (*MemoryCache) Count ¶
func (memory *MemoryCache) Count() int
func (*MemoryCache) Get ¶
func (memory *MemoryCache) Get(key string) (value interface{}, ok bool)
func (*MemoryCache) Remove ¶
func (memory *MemoryCache) Remove(key string) (value interface{}, ok bool)
type MemoryCacheStore ¶
func NewMemoryCacheStore ¶
func (*MemoryCacheStore) Add ¶
func (store *MemoryCacheStore) Add(item *CacheItem)
func (*MemoryCacheStore) AddWithAbsoluteExpiration ¶
func (store *MemoryCacheStore) AddWithAbsoluteExpiration(key string, value interface{}, expiration time.Time)
func (*MemoryCacheStore) AddWithSlidingExpiration ¶
func (store *MemoryCacheStore) AddWithSlidingExpiration(key string, value interface{}, expiration time.Duration)
func (*MemoryCacheStore) Clear ¶
func (store *MemoryCacheStore) Clear()
func (*MemoryCacheStore) Close ¶
func (store *MemoryCacheStore) Close()
func (*MemoryCacheStore) ContainsKey ¶
func (store *MemoryCacheStore) ContainsKey(key string) bool
func (*MemoryCacheStore) Count ¶
func (store *MemoryCacheStore) Count() int
func (*MemoryCacheStore) GetValue ¶
func (store *MemoryCacheStore) GetValue(key string) (value interface{}, ok bool)
func (*MemoryCacheStore) Remove ¶
func (store *MemoryCacheStore) Remove(key string) (value interface{}, ok bool)
type NoSlidingExpiration ¶
基于持续时间或定义的时间窗口过期也被称为可调过期。 通常情况下,逐出基于可调过期的项的缓存实现将删除在指定的时间段未被访问的项。 插入到缓存与某个缓存项NoSlidingExpiration字段值设置为过期值应该永远不会收回由于非活动的滑动时间窗口中。 但是,如果具有绝对到期,或某些其他逐出事件发生时,此类更改监视器或内存压力,可以逐出缓存项。
Source Files ¶
Click to show internal directories.
Click to hide internal directories.