Documentation
¶
Index ¶
- Constants
- func GetInt64(key string, getFunc func() (int64, error)) (int64, error)
- func GetString(key string, getFunc func() (string, error)) (string, error)
- func GetWithContextCache[T, K any](ctx context.Context, groupKey string, targetKey K, ...) (T, error)
- func GetWithEphemeralCache[T, K any](ctx context.Context, c *EphemeralCache, groupKey string, targetKey K, ...) (T, error)
- func Init() error
- func Remove(key string)
- func Test() (time.Duration, error)
- func WithCacheContext(ctx context.Context) context.Context
- type EphemeralCache
- type GetJSONError
- type MemoryItem
- type RedisCacher
- func (c *RedisCacher) Decr(key string) error
- func (c *RedisCacher) Delete(key string) error
- func (c *RedisCacher) Flush() error
- func (c *RedisCacher) Get(key string) any
- func (c *RedisCacher) Incr(key string) error
- func (c *RedisCacher) IsExist(key string) bool
- func (c *RedisCacher) Ping() error
- func (c *RedisCacher) Put(key string, val any, expire int64) error
- func (c *RedisCacher) StartAndGC(opts cache.Options) error
- type StringCache
- type TwoQueueCache
- func (c *TwoQueueCache) Decr(key string) error
- func (c *TwoQueueCache) Delete(key string) error
- func (c *TwoQueueCache) Flush() error
- func (c *TwoQueueCache) Get(key string) any
- func (c *TwoQueueCache) Incr(key string) error
- func (c *TwoQueueCache) IsExist(key string) bool
- func (c *TwoQueueCache) Ping() error
- func (c *TwoQueueCache) Put(key string, val any, timeout int64) error
- func (c *TwoQueueCache) StartAndGC(opts mc.Options) error
- type TwoQueueCacheConfig
Constants ¶
const ( // SlowCacheThreshold marks cache tests as slow // set to 30ms per discussion: https://github.com/go-gitea/gitea/issues/33190 // TODO: Replace with metrics histogram SlowCacheThreshold = 30 * time.Millisecond )
Variables ¶
This section is empty.
Functions ¶
func GetString ¶
GetString returns the key value from cache with callback when no key exists in cache
func GetWithContextCache ¶
func GetWithContextCache[T, K any](ctx context.Context, groupKey string, targetKey K, f func(context.Context, K) (T, error)) (T, error)
GetWithContextCache returns the cache value of the given key in the given context. FIXME: in some cases, the "context cache" should not be used, because it has uncontrollable behaviors For example, these calls: * GetWithContextCache(TargetID) -> OtherCodeCreateModel(TargetID) -> GetWithContextCache(TargetID) Will cause the second call is not able to get the correct created target. UNLESS it is certain that the target won't be changed during the request, DO NOT use it.
func GetWithEphemeralCache ¶
Types ¶
type EphemeralCache ¶
type EphemeralCache struct {
// contains filtered or unexported fields
}
EphemeralCache is a cache that can be used to store data in a request level context This is useful for caching data that is expensive to calculate and is likely to be used multiple times in a request.
func GetContextCache ¶
func GetContextCache(ctx context.Context) *EphemeralCache
func NewEphemeralCache ¶
func NewEphemeralCache(checkLifeTime ...time.Duration) *EphemeralCache
func (*EphemeralCache) Delete ¶
func (cc *EphemeralCache) Delete(tp, key any)
func (*EphemeralCache) Put ¶
func (cc *EphemeralCache) Put(tp, key, value any)
type GetJSONError ¶
type GetJSONError struct {
// contains filtered or unexported fields
}
func (*GetJSONError) ToError ¶
func (e *GetJSONError) ToError() error
type MemoryItem ¶
MemoryItem represents a memory cache item.
type RedisCacher ¶
type RedisCacher struct {
// contains filtered or unexported fields
}
RedisCacher represents a redis cache adapter implementation.
func (*RedisCacher) Decr ¶
func (c *RedisCacher) Decr(key string) error
Decr decreases cached int-type value by given key as a counter.
func (*RedisCacher) Delete ¶
func (c *RedisCacher) Delete(key string) error
Delete deletes cached value by given key.
func (*RedisCacher) Get ¶
func (c *RedisCacher) Get(key string) any
Get gets cached value by given key.
func (*RedisCacher) Incr ¶
func (c *RedisCacher) Incr(key string) error
Incr increases cached int-type value by given key as a counter.
func (*RedisCacher) IsExist ¶
func (c *RedisCacher) IsExist(key string) bool
IsExist returns true if cached value exists.
func (*RedisCacher) Put ¶
func (c *RedisCacher) Put(key string, val any, expire int64) error
Put puts value (string type) into cache with key and expire time. If expired is 0, it lives forever.
func (*RedisCacher) StartAndGC ¶
func (c *RedisCacher) StartAndGC(opts cache.Options) error
StartAndGC starts GC routine based on config string settings. AdapterConfig: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180,hset_name=MacaronCache,prefix=cache:
type StringCache ¶
type StringCache interface {
Ping() error
Get(key string) (string, bool)
Put(key, value string, ttl int64) error
Delete(key string) error
IsExist(key string) bool
PutJSON(key string, v any, ttl int64) error
GetJSON(key string, ptr any) (exist bool, err *GetJSONError)
ChiCache() chi_cache.Cache
}
func NewStringCache ¶
func NewStringCache(cacheConfig setting.Cache) (StringCache, error)
type TwoQueueCache ¶
type TwoQueueCache struct {
// contains filtered or unexported fields
}
TwoQueueCache represents a LRU 2Q cache adapter implementation
func (*TwoQueueCache) Decr ¶
func (c *TwoQueueCache) Decr(key string) error
Decr decreases cached int-type value by given key as a counter.
func (*TwoQueueCache) Delete ¶
func (c *TwoQueueCache) Delete(key string) error
Delete deletes cached value by given key.
func (*TwoQueueCache) Get ¶
func (c *TwoQueueCache) Get(key string) any
Get gets cached value by given key.
func (*TwoQueueCache) Incr ¶
func (c *TwoQueueCache) Incr(key string) error
Incr increases cached int-type value by given key as a counter.
func (*TwoQueueCache) IsExist ¶
func (c *TwoQueueCache) IsExist(key string) bool
IsExist returns true if cached value exists.
func (*TwoQueueCache) Put ¶
func (c *TwoQueueCache) Put(key string, val any, timeout int64) error
Put puts value into cache with key and expire time.
func (*TwoQueueCache) StartAndGC ¶
func (c *TwoQueueCache) StartAndGC(opts mc.Options) error
StartAndGC starts GC routine based on config string settings.
type TwoQueueCacheConfig ¶
type TwoQueueCacheConfig struct {
Size int `ini:"SIZE" json:"size"`
RecentRatio float64 `ini:"RECENT_RATIO" json:"recent_ratio"`
GhostRatio float64 `ini:"GHOST_RATIO" json:"ghost_ratio"`
}
TwoQueueCacheConfig describes the configuration for TwoQueueCache