Documentation ¶
Index ¶
- Constants
- Variables
- func FileGetContents(filename string) ([]byte, error)
- func FilePutContents(filename string, content []byte) error
- func GetBool(v interface{}) bool
- func GetFloat64(v interface{}) float64
- func GetInt(v interface{}) int
- func GetInt64(v interface{}) int64
- func GetString(v interface{}) string
- func GobDecode(data []byte, to *FileCacheItem) error
- func GobEncode(data interface{}) ([]byte, error)
- type BloomFilter
- type BloomFilterCache
- type Cache
- func NewFileCache(opts ...FileCacheOptions) (Cache, error)
- func NewMemoryCache(interval int) Cache
- func NewRandomExpireCache(adapter Cache, opts ...RandomExpireCacheOption) Cache
- func NewReadThroughCache(cache Cache, expiration time.Duration, ...) (Cache, error)
- func NewSingleflightCache(c Cache, expiration time.Duration, ...) (Cache, error)
- type FileCache
- func (fc *FileCache) ClearAll(context.Context) error
- func (fc *FileCache) Decr(ctx context.Context, key string) error
- func (fc *FileCache) Delete(ctx context.Context, key string) error
- func (fc *FileCache) Get(ctx context.Context, key string) (interface{}, error)
- func (fc *FileCache) GetMulti(ctx context.Context, keys []string) ([]interface{}, error)
- func (fc *FileCache) Incr(ctx context.Context, key string) error
- func (fc *FileCache) Init() error
- func (fc *FileCache) IsExist(ctx context.Context, key string) (bool, error)
- func (fc *FileCache) Put(ctx context.Context, key string, val interface{}, timeout time.Duration) error
- type FileCacheItem
- type FileCacheOptions
- type MemoryCache
- func (bc *MemoryCache) ClearAll(context.Context) error
- func (bc *MemoryCache) Decr(ctx context.Context, key string) error
- func (bc *MemoryCache) Delete(ctx context.Context, key string) error
- func (bc *MemoryCache) Get(ctx context.Context, key string) (interface{}, error)
- func (bc *MemoryCache) GetMulti(ctx context.Context, keys []string) ([]interface{}, error)
- func (bc *MemoryCache) Incr(ctx context.Context, key string) error
- func (bc *MemoryCache) IsExist(ctx context.Context, key string) (bool, error)
- func (bc *MemoryCache) Put(ctx context.Context, key string, val interface{}, timeout time.Duration) error
- type MemoryItem
- type RandomExpireCache
- type RandomExpireCacheOption
- type SingleflightCache
- type WriteThroughCache
Constants ¶
const ( MinUint32 uint32 = 0 MinUint64 uint64 = 0 )
Variables ¶
var ( ErrIncrementOverflow = berror.Error(IncrementOverflow, "this incr invocation will overflow.") ErrDecrementOverflow = berror.Error(DecrementOverflow, "this decr invocation will overflow.") ErrNotIntegerType = berror.Error(NotIntegerType, "item val is not (u)int (u)int32 (u)int64") )
var ( ErrKeyExpired = berror.Error(KeyExpired, "the key is expired") ErrKeyNotExist = berror.Error(KeyNotExist, "the key isn't exist") )
var ( FileCachePath = "cache" // cache directory FileCacheFileSuffix = ".bin" // cache file suffix FileCacheDirectoryLevel = 2 // cache file deep level if auto generated cache files. FileCacheEmbedExpiry time.Duration // cache expire time, default is no expire forever. )
FileCache Config
var CreateFileCacheDirFailed = berror.DefineCode(4002009, moduleName, "CreateFileCacheDirFailed", `
Beego failed to create file cache directory. There are two cases:
1. You pass invalid CachePath parameter. Please check your input.
2. Beego doesn't have the permission to create this directory. Please check your file mode.
`)
var DecrementOverflow = berror.DefineCode(4002005, moduleName, "DecrementOverflow", `
The decrement operation will overflow.
`)
var DeleteFileCacheItemFailed = berror.DefineCode(5002001, moduleName, "DeleteFileCacheItemFailed", `
Beego try to delete file cache item failed.
Please check whether Beego generated file correctly.
And then confirm whether this file is already deleted by other processes or other people.
`)
var DialFailed = berror.DefineCode(5002005, moduleName, "DialFailed", `
When Beego try to dial to remote servers, it failed. Please check your connection info and network state, server state.
`)
var GobEncodeDataFailed = berror.DefineCode(4002013, moduleName, "GobEncodeDataFailed", `
Beego could not encode the data to GOB byte array. In general, the data type is invalid.
For example, GOB doesn't support function type.
Basic types, string, structure, structure pointer are supported.
`)
var IncrementOverflow = berror.DefineCode(4002004, moduleName, "IncrementOverflow", `
The increment operation will overflow.
`)
var InvalidFileCachePath = berror.DefineCode(4002010, moduleName, "InvalidFilePath", `
The file path of FileCache is invalid. Please correct the config.
`)
var InvalidGobEncodedData = berror.DefineCode(4002012, moduleName, "InvalidEncodedData", `
The data is invalid. When you try to decode the invalid data, you got this error.
Please confirm that the data is encoded by GOB correctly.
`)
var InvalidInitParameters = berror.DefineCode(4002025, moduleName, "InvalidInitParameters", `
Invalid init cache parameters.
You can check the related function to confirm that if you pass correct parameters or configure to initiate a Cache instance.
`)
var InvalidLoadFunc = berror.DefineCode(4002023, moduleName, "InvalidLoadFunc", `
Invalid load function for read-through pattern decorator.
You should pass a valid(non-nil) load function when initiate the decorator instance.
`)
var InvalidMemCacheValue = berror.DefineCode(4002019, moduleName, "InvalidMemCacheValue", `
The value must be string or byte[], please check your input.
`)
var InvalidSsdbCacheValue = berror.DefineCode(4002022, moduleName, "InvalidSsdbCacheValue", `
SSDB cache only accept string value. Please check your input.
`)
var KeyExpired = berror.DefineCode(4002014, moduleName, "KeyExpired", `
Cache key is expired.
You should notice that, a key is expired and then it may be deleted by GC goroutine.
So when you query a key which may be expired, you may got this code, or KeyNotExist.
`)
var KeyNotExist = berror.DefineCode(4002015, moduleName, "KeyNotExist", `
Key not found.
`)
var LoadFuncFailed = berror.DefineCode(4002024, moduleName, "LoadFuncFailed", `
Failed to load data, please check whether the loadfunc is correct
`)
var MemCacheCurdFailed = berror.DefineCode(5002002, moduleName, "MemCacheError", `
When you want to get, put, delete key-value from remote memcache servers, you may get error:
1. You pass invalid servers address, so Beego could not connect to remote server;
2. The servers address is correct, but there is some net issue. Typically there is some firewalls between application and memcache server;
3. Key is invalid. The key's length should be less than 250 and must not contains special characters;
4. The response from memcache server is invalid;
`)
var MultiGetFailed = berror.DefineCode(4002016, moduleName, "MultiGetFailed", `
Get multiple keys failed. Please check the detail msg to find out the root cause.
`)
var NotIntegerType = berror.DefineCode(4002006, moduleName, "NotIntegerType", `
The type of value is not (u)int (u)int32 (u)int64.
When you want to call Incr or Decr function of Cache API, you must confirm that the value's type is one of (u)int (u)int32 (u)int64.
`)
var PersistCacheFailed = berror.DefineCode(4002026, moduleName, "PersistCacheFailed", `
Failed to execute the StoreFunc.
Please check the log to make sure the StoreFunc works for the specific key and value.
`)
var ReadFileCacheContentFailed = berror.DefineCode(4002011, moduleName, "ReadFileCacheContentFailed", `
Usually you won't got this error. It means that Beego cannot read the data from the file.
You need to check whether the file exist. Sometimes it may be deleted by other processes.
If the file exists, please check the permission that Beego is able to read data from the file.
`)
var RedisCacheCurdFailed = berror.DefineCode(5002003, moduleName, "RedisCacheCurdFailed", `
When Beego uses client to send request to redis server, it failed.
1. The server addresses is invalid;
2. Network issue, firewall issue or network is unstable;
3. Client failed to manage connection. In extreme cases, Beego's redis client didn't maintain connections correctly, for example, Beego try to send request via closed connection;
4. The request are huge and redis server spent too much time to process it, and client is timeout;
In general, if you always got this error whatever you do, in most cases, it was caused by network issue.
You could check your network state, and confirm that firewall rules are correct.
`)
var SsdbBadResponse = berror.DefineCode(5002007, moduleName, "SsdbBadResponse", `
The reponse from SSDB server is invalid.
Usually it indicates something wrong on server side.
`)
var SsdbCacheCurdFailed = berror.DefineCode(5002006, moduleName, "SsdbCacheCurdFailed", `
When you try to use SSDB cache, it failed. There are many cases:
1. servers unavailable;
2. network issue, including network unstable, firewall;
3. connection issue;
4. request are huge and servers spent too much time to process it, got timeout;
`)
Functions ¶
func FileGetContents ¶
FileGetContents Reads bytes from a file. if non-existent, create this file.
func FilePutContents ¶
FilePutContents puts bytes into a file. if non-existent, create this file.
func GobDecode ¶
func GobDecode(data []byte, to *FileCacheItem) error
GobDecode Gob decodes a file cache item.
Types ¶
type BloomFilter ¶
type BloomFilterCache ¶
type BloomFilterCache struct { Cache BloomFilter // contains filtered or unexported fields }
func NewBloomFilterCache ¶
type Cache ¶
type Cache interface { // Get a cached value by key. Get(ctx context.Context, key string) (interface{}, error) // GetMulti is a batch version of Get. GetMulti(ctx context.Context, keys []string) ([]interface{}, error) // Put Set a cached value with key and expire time. Put(ctx context.Context, key string, val interface{}, timeout time.Duration) error // Delete cached value by key. // Should not return error if key not found Delete(ctx context.Context, key string) error // Incr Increment a cached int value by key, as a counter. Incr(ctx context.Context, key string) error // Decr Decrement a cached int value by key, as a counter. Decr(ctx context.Context, key string) error // IsExist Check if a cached value exists or not. // if key is expired, return (false, nil) IsExist(ctx context.Context, key string) (bool, error) // ClearAll Clear all cache. ClearAll(ctx context.Context) error }
Cache interface contains all behaviors for cache adapter.
func NewFileCache ¶
func NewFileCache(opts ...FileCacheOptions) (Cache, error)
NewFileCache creates a new file cache with no config. The level and expiry need to be set in the method StartAndGC as config string.
func NewMemoryCache ¶
NewMemoryCache returns a new MemoryCache.
func NewRandomExpireCache ¶
func NewRandomExpireCache(adapter Cache, opts ...RandomExpireCacheOption) Cache
NewRandomExpireCache return random expire cache struct
type FileCache ¶
FileCache is cache adapter for file storage.
func (*FileCache) Get ¶
Get value from file cache. if nonexistent or expired return an empty string.
func (*FileCache) GetMulti ¶
GetMulti gets values from file cache. if nonexistent or expired return an empty string.
type FileCacheItem ¶
FileCacheItem is basic unit of file cache adapter which contains data and expire time.
type FileCacheOptions ¶
type FileCacheOptions func(c *FileCache)
func FileCacheWithCachePath ¶
func FileCacheWithCachePath(cachePath string) FileCacheOptions
FileCacheWithCachePath configures cachePath for FileCache
func FileCacheWithDirectoryLevel ¶
func FileCacheWithDirectoryLevel(directoryLevel int) FileCacheOptions
FileCacheWithDirectoryLevel configures directoryLevel for FileCache
func FileCacheWithEmbedExpiry ¶
func FileCacheWithEmbedExpiry(fileCacheEmbedExpiry int) FileCacheOptions
FileCacheWithEmbedExpiry configures fileCacheEmbedExpiry for FileCache
func FileCacheWithFileSuffix ¶
func FileCacheWithFileSuffix(fileSuffix string) FileCacheOptions
FileCacheWithFileSuffix configures fileSuffix for FileCache
type MemoryCache ¶
type MemoryCache struct { sync.RWMutex Every int // run an expiration check Every clock time // contains filtered or unexported fields }
MemoryCache is a memory cache adapter. Contains a RW locker for safe map storage.
func (*MemoryCache) ClearAll ¶
func (bc *MemoryCache) ClearAll(context.Context) error
ClearAll deletes all cache in memory.
func (*MemoryCache) Decr ¶
func (bc *MemoryCache) Decr(ctx context.Context, key string) error
Decr decreases counter in memory.
func (*MemoryCache) Delete ¶
func (bc *MemoryCache) Delete(ctx context.Context, key string) error
Delete cache in memory. If the key is not found, it will not return error
func (*MemoryCache) Get ¶
func (bc *MemoryCache) Get(ctx context.Context, key string) (interface{}, error)
Get returns cache from memory. If non-existent or expired, return nil.
func (*MemoryCache) GetMulti ¶
func (bc *MemoryCache) GetMulti(ctx context.Context, keys []string) ([]interface{}, error)
GetMulti gets caches from memory. If non-existent or expired, return nil.
func (*MemoryCache) Incr ¶
func (bc *MemoryCache) Incr(ctx context.Context, key string) error
Incr increases cache counter in memory. Supports int,int32,int64,uint,uint32,uint64.
type MemoryItem ¶
type MemoryItem struct {
// contains filtered or unexported fields
}
MemoryItem stores memory cache item.
type RandomExpireCache ¶
type RandomExpireCache struct { Cache // contains filtered or unexported fields }
RandomExpireCache prevent cache batch invalidation Cache random time offset expired
type RandomExpireCacheOption ¶
type RandomExpireCacheOption func(*RandomExpireCache)
RandomExpireCacheOption implement genreate random time offset expired option
func WithRandomExpireCacheOffsetFunc ¶
func WithRandomExpireCacheOffsetFunc(fn func() time.Duration) RandomExpireCacheOption
WithRandomExpireCacheOffsetFunc returns a RandomExpireCacheOption that configures the offset function
type SingleflightCache ¶
type SingleflightCache struct { Cache // contains filtered or unexported fields }
SingleflightCache This is a very simple decorator mode
type WriteThroughCache ¶
type WriteThroughCache struct { Cache // contains filtered or unexported fields }
func NewWriteThroughCache ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal/mock
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |