Documentation
¶
Index ¶
- Constants
- func New(path string, ext ...string) gcache.Adapter
- type FileCache
- func (c *FileCache) Clear(ctx context.Context) error
- func (c *FileCache) Close(ctx context.Context) error
- func (c *FileCache) Contains(ctx context.Context, key interface{}) (bool, error)
- func (c *FileCache) Data(ctx context.Context) (map[interface{}]interface{}, error)
- func (c *FileCache) Get(ctx context.Context, key interface{}) (interface{}, error)
- func (c *FileCache) GetExpire(ctx context.Context, key interface{}) (time.Duration, error)
- func (c *FileCache) GetOrSet(ctx context.Context, key interface{}, value interface{}, ...) (interface{}, error)
- func (c *FileCache) GetOrSetFunc(ctx context.Context, key interface{}, f func() (interface{}, error), ...) (interface{}, error)
- func (c *FileCache) GetOrSetFuncLock(ctx context.Context, key interface{}, f func() (interface{}, error), ...) (interface{}, error)
- func (c *FileCache) Keys(ctx context.Context) ([]interface{}, error)
- func (c *FileCache) Remove(ctx context.Context, keys ...interface{}) (value interface{}, err error)
- func (c *FileCache) Set(ctx context.Context, key interface{}, value interface{}, ...) error
- func (c *FileCache) SetIfNotExist(ctx context.Context, key interface{}, value interface{}, ...) (bool, error)
- func (c *FileCache) Sets(ctx context.Context, data map[interface{}]interface{}, duration time.Duration) error
- func (c *FileCache) Size(ctx context.Context) (size int, err error)
- func (c *FileCache) Update(ctx context.Context, key interface{}, value interface{}) (oldValue interface{}, exist bool, err error)
- func (c *FileCache) UpdateExpire(ctx context.Context, key interface{}, duration time.Duration) (oldDuration time.Duration, err error)
- func (c *FileCache) Values(ctx context.Context) ([]interface{}, error)
Constants ¶
const (
DEFAULT_EXT = ".tmp"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FileCache ¶
type FileCache struct {
// contains filtered or unexported fields
}
func (*FileCache) Clear ¶
Clear clears all data of the cache. Note that this function is sensitive and should be carefully used. 小心使用,将删除所有
func (*FileCache) Contains ¶
Contains returns true if <key> exists in the cache, or else returns false.
func (*FileCache) Data ¶
Data returns a copy of all key-value pairs in the cache as map type. Note that this function may leads lots of memory usage, you can implement this function if necessary.
func (*FileCache) Get ¶
Get retrieves and returns the associated value of given <key>. It returns nil if it does not exist or its value is nil.
func (*FileCache) GetExpire ¶
GetExpire retrieves and returns the expiration of <key> in the cache.
It returns 0 if the <key> does not expire. It returns -1 if the <key> does not exist in the cache.
func (*FileCache) GetOrSet ¶
func (c *FileCache) GetOrSet(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (interface{}, error)
GetOrSet retrieves and returns the value of <key>, or sets <key>-<value> pair and returns <value> if <key> does not exist in the cache. The key-value pair expires after <duration>.
It does not expire if <duration> == 0. It deletes the <key> if <duration> < 0 or given <value> is nil, but it does nothing if <value> is a function and the function result is nil.
func (*FileCache) GetOrSetFunc ¶
func (c *FileCache) GetOrSetFunc(ctx context.Context, key interface{}, f func() (interface{}, error), duration time.Duration) (interface{}, error)
GetOrSetFunc retrieves and returns the value of <key>, or sets <key> with result of function <f> and returns its result if <key> does not exist in the cache. The key-value pair expires after <duration>.
It does not expire if <duration> == 0. It deletes the <key> if <duration> < 0 or given <value> is nil, but it does nothing if <value> is a function and the function result is nil.
func (*FileCache) GetOrSetFuncLock ¶
func (c *FileCache) GetOrSetFuncLock(ctx context.Context, key interface{}, f func() (interface{}, error), duration time.Duration) (interface{}, error)
GetOrSetFuncLock retrieves and returns the value of <key>, or sets <key> with result of function <f> and returns its result if <key> does not exist in the cache. The key-value pair expires after <duration>.
It does not expire if <duration> == 0. It does nothing if function <f> returns nil.
Note that the function <f> should be executed within writing mutex lock for concurrent safety purpose.
func (*FileCache) Remove ¶
Remove deletes one or more keys from cache, and returns its value. If multiple keys are given, it returns the value of the last deleted item.
func (*FileCache) Set ¶
func (c *FileCache) Set(ctx context.Context, key interface{}, value interface{}, duration time.Duration) error
Set sets cache with <key>-<value> pair, which is expired after <duration>.
It does not expire if <duration> == 0. It deletes the <key> if <duration> < 0.
func (*FileCache) SetIfNotExist ¶
func (c *FileCache) SetIfNotExist(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (bool, error)
SetIfNotExist sets cache with <key>-<value> pair which is expired after <duration> if <key> does not exist in the cache. It returns true the <key> dose not exist in the cache and it sets <value> successfully to the cache, or else it returns false.
The parameter <value> can be type of <func() interface{}>, but it dose nothing if its result is nil.
It does not expire if <duration> == 0. It deletes the <key> if <duration> < 0 or given <value> is nil.
func (*FileCache) Sets ¶
func (c *FileCache) Sets(ctx context.Context, data map[interface{}]interface{}, duration time.Duration) error
Sets batch sets cache with key-value pairs by <data>, which is expired after <duration>.
It does not expire if <duration> == 0. It deletes the keys of <data> if <duration> < 0 or given <value> is nil.
func (*FileCache) Update ¶
func (c *FileCache) Update(ctx context.Context, key interface{}, value interface{}) (oldValue interface{}, exist bool, err error)
Update updates the value of <key> without changing its expiration and returns the old value. The returned value <exist> is false if the <key> does not exist in the cache.
It deletes the <key> if given <value> is nil. It does nothing if <key> does not exist in the cache.
func (*FileCache) UpdateExpire ¶
func (c *FileCache) UpdateExpire(ctx context.Context, key interface{}, duration time.Duration) (oldDuration time.Duration, err error)
UpdateExpire updates the expiration of <key> and returns the old expiration duration value.
It returns -1 and does nothing if the <key> does not exist in the cache. It deletes the <key> if <duration> < 0.