Documentation ¶
Index ¶
- Variables
- func FileGetContents(filename string) ([]byte, error)
- func FilePutContents(filename string, content []byte) error
- func GobDecode(data []byte, to *FileCacheItem) error
- func GobEncode(data interface{}) ([]byte, error)
- func NewFileCache() cache.Cache
- 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) Fetch(ctx context.Context, keys []string) ([]any, error)
- func (fc *FileCache) Get(ctx context.Context, key 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
- func (fc *FileCache) StartAndGC(config string) error
- type FileCacheItem
Constants ¶
This section is empty.
Variables ¶
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
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.
func NewFileCache ¶
NewFileCache creates a new file cache with no config. The level and expiry need to be set in the method StartAndGC as config string.
Types ¶
type FileCache ¶
FileCache is cache adapter for file storage.
func (*FileCache) Fetch ¶
Fetch gets values from file cache. if nonexistent or expired return an empty string.
func (*FileCache) Get ¶
Get value from file cache. if nonexistent or expired return an empty string.
func (*FileCache) Put ¶
func (fc *FileCache) Put(ctx context.Context, key string, val interface{}, timeout ...time.Duration) error
Put value into file cache. timeout: how long this file should be kept in ms if timeout equals fc.EmbedExpiry(default is 0), cache this item forever.
func (*FileCache) StartAndGC ¶
StartAndGC starts gc for file cache. config must be in the format {CachePath:"/cache","FileSuffix":".bin","DirectoryLevel":"2","EmbedExpiry":"0"}