Documentation
¶
Index ¶
- func IsAlreadyExists(err error) bool
- func IsClearedCache(err error) bool
- func IsDoesNotExist(err error) bool
- func IsInvalidKeyType(err error) bool
- func IsInvalidMessage(err error) bool
- func IsInvalidValueType(err error) bool
- func IsNilUpdateFunc(err error) bool
- func IsNilValue(err error) bool
- func IsNonPositivePeriod(err error) bool
- func IsUnexpectedError(err error) bool
- func IsUnrecoverableValue(err error) bool
- func NewDirectoryCache(dir string) (*directoryCache, error)
- func NewLfu(capacity int) *lfuCache
- func NewLfuWithCustomCache(capacity int, cache Cache) (*lfuCache, error)
- func NewLru(capacity int) *lruCache
- func NewLruWithCustomCache(capacity int, cache Cache) (*lruCache, error)
- func NewMapCache() *mapCache
- type Cache
- type ExpiringCache
- type RedisCache
- func (r *RedisCache) Clear() error
- func (r *RedisCache) Expire(key interface{}, ttl time.Duration) error
- func (r *RedisCache) Get(key interface{}) (interface{}, error)
- func (r *RedisCache) Keys() ([]interface{}, error)
- func (r *RedisCache) Remove(key interface{}) error
- func (r *RedisCache) Replace(key, val interface{}) error
- func (r *RedisCache) ReplaceWithExpiration(key, val interface{}, ttl time.Duration) error
- func (r *RedisCache) Store(key, val interface{}) error
- func (r *RedisCache) StoreWithExpiration(key, val interface{}, ttl time.Duration) error
- type UpdatingCache
- type UpdatingExpiringCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyExists ¶ added in v0.1.13
func IsClearedCache ¶ added in v0.1.13
func IsDoesNotExist ¶ added in v0.1.13
func IsInvalidKeyType ¶ added in v0.1.13
func IsInvalidMessage ¶ added in v0.1.15
func IsInvalidValueType ¶ added in v0.1.13
func IsNilUpdateFunc ¶ added in v0.1.13
func IsNilValue ¶ added in v0.1.13
func IsNonPositivePeriod ¶ added in v0.1.13
func IsUnexpectedError ¶ added in v0.1.15
func IsUnrecoverableValue ¶ added in v0.1.13
func NewDirectoryCache ¶ added in v0.1.13
Create a new Cache object that is backed up by a directory.
If dir does not exist, it will be created.
func NewLfu ¶ added in v0.2.0
func NewLfu(capacity int) *lfuCache
NewLfu creates a new lfuCache instance using mapCache.
func NewLfuWithCustomCache ¶ added in v0.2.0
NewLfuWithCustomCache creates a new lfuCache with custom cache.
func NewLru ¶ added in v0.2.0
func NewLru(capacity int) *lruCache
NewLru creates a new lruCache instance using mapCache.
func NewLruWithCustomCache ¶ added in v0.2.0
NewLruWithCustomCache creates a new lruCache with custom cache.
func NewMapCache ¶
func NewMapCache() *mapCache
NewMapCache creates a new Cache object that is backed by a map.
Types ¶
type Cache ¶
type Cache interface {
// Store a value permanently.
Store(key, val interface{}) error
// Get a value.
Get(key interface{}) (interface{}, error)
// Remove a value.
Remove(key interface{}) error
// Replace a value.
Replace(key, val interface{}) error
// Clears the cache.
Clear() error
// Get all keys from the cache.
Keys() ([]interface{}, error)
}
type ExpiringCache ¶ added in v0.1.13
type ExpiringCache interface {
Cache
// Store a value that will be removed after the specified ttl.
StoreWithExpiration(key, val interface{}, ttl time.Duration) error
// Replaces the value of a key.
ReplaceWithExpiration(key, val interface{}, ttl time.Duration) error
// Expire resets and updates the ttl of a value.
Expire(key interface{}, ttl time.Duration) error
}
type RedisCache ¶ added in v0.2.0
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache is a client that implements Cache interface.
func NewRedisCache ¶ added in v0.2.0
func NewRedisCache(address, password string, db int) *RedisCache
NewRedisCache creates and returns a reference to a RedisCache instance.
func (*RedisCache) Clear ¶ added in v0.2.0
func (r *RedisCache) Clear() error
Clear all values that maintained by this RedisCache instance.
func (*RedisCache) Expire ¶ added in v0.2.0
func (r *RedisCache) Expire(key interface{}, ttl time.Duration) error
Expire a key-value pair.
func (*RedisCache) Get ¶ added in v0.2.0
func (r *RedisCache) Get(key interface{}) (interface{}, error)
Get a value from redis.
func (*RedisCache) Keys ¶ added in v0.2.0
func (r *RedisCache) Keys() ([]interface{}, error)
Keys return all keys that maintained by this RedisCache instance.
func (*RedisCache) Remove ¶ added in v0.2.0
func (r *RedisCache) Remove(key interface{}) error
Remove a value from redis.
func (*RedisCache) Replace ¶ added in v0.2.0
func (r *RedisCache) Replace(key, val interface{}) error
Replace an existing value in redis.
func (*RedisCache) ReplaceWithExpiration ¶ added in v0.2.0
func (r *RedisCache) ReplaceWithExpiration(key, val interface{}, ttl time.Duration) error
ReplaceWithExpiration replaces a key-value pair in redis for limited time.
func (*RedisCache) Store ¶ added in v0.2.0
func (r *RedisCache) Store(key, val interface{}) error
Store permanent value in redis.
func (*RedisCache) StoreWithExpiration ¶ added in v0.2.0
func (r *RedisCache) StoreWithExpiration(key, val interface{}, ttl time.Duration) error
StoreWithExpiration stores a key-value pair in redis for limited time.
type UpdatingCache ¶ added in v0.1.13
type UpdatingCache interface {
Cache
// Stores a value and repeatedly updates it.
StoreWithUpdate(key, initialValue interface{},
updateFunc func(currValue interface{}) interface{},
period time.Duration) error
// Replaces a value and repeatedly updates it.
ReplaceWithUpdate(key, initialValue interface{},
updateFunc func(currValue interface{}) interface{},
period time.Duration) error
}
type UpdatingExpiringCache ¶ added in v0.1.13
type UpdatingExpiringCache interface {
UpdatingCache
ExpiringCache
}