Import path:
gitlab.soludian.com/soludian/fountain/libs/cache/file_cache
file_cache
import "gitlab.soludian.com/soludian/fountain/libs/cache/file_cache"Index
- Constants
- Variables
- func FileGetContents(filename string) ([]byte, error)
- func FilePutContents(filename string, content []byte) error
- func GobDecode(data []byte, to *entry) error
- func GobEncode(data any) ([]byte, error)
- func NewFileCache() cache.Cache
- type Cache
- func (rc *Cache) ClearAll(context.Context) error
- func (rc *Cache) Close() error
- func (rc *Cache) Decr(key string) (int64, error)
- func (rc *Cache) Delete(key string) error
- func (rc *Cache) Get(key string) ([]byte, error)
- func (rc *Cache) GetDefaultConfig() string
- func (rc *Cache) GetMulti(keys []string) ([][]byte, error)
- func (rc *Cache) Has(key string) bool
- func (rc *Cache) Incr(key string) (int64, error)
- func (rc *Cache) Init() error
- func (rc *Cache) Peek(key string) (any, error)
- func (rc *Cache) PeekMulti(keys []string) ([]any, error)
- func (rc *Cache) Put(key string, val any, ttl time.Duration) error
- func (rc *Cache) PutMulti(values map[string]any, timeout time.Duration) error
- func (rc *Cache) Reset() error
- func (rc *Cache) Set(key string, val []byte, ttl time.Duration) error
- func (rc *Cache) SetMulti(values map[string][]byte, ttl time.Duration) error
- func (rc *Cache) SetName(name string)
- func (rc *Cache) StartAndGC(configs ...string) error
Constants
const DefaultConfig = `{"cache_path":"/cache","file_suffix":".bin","directory_level":"2","embed_expiry":"0"}`const KPackageName = "file_cache"Variables
var (
FileCachePath = ".file_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.
)func FileGetContents
func FileGetContents(filename string) ([]byte, error)FileGetContents Reads bytes from a file. if non-existent, create this file.
func FilePutContents
func FilePutContents(filename string, content []byte) errorFilePutContents puts bytes into a file. if non-existent, create this file.
func GobDecode
func GobDecode(data []byte, to *entry) errorGobDecode Gob decodes a file cache item.
func GobEncode
func GobEncode(data any) ([]byte, error)GobEncode Gob encodes a file cache item.
func NewFileCache
func NewFileCache() cache.CacheNewFileCache creates a new file cache with no config. The level and expiry need to be set in the method StartAndGC as config string.
type Cache
FileCache is cache adapter for file storage.
type Cache struct {
CachePath string
FileSuffix string
DirectoryLevel int
EmbedExpiry int
// contains filtered or unexported fields
}func (*Cache) ClearAll
func (rc *Cache) ClearAll(context.Context) errorClearAll cleans cached files (not implemented)
func (*Cache) Close
func (rc *Cache) Close() errorClose the database
func (*Cache) Decr
func (rc *Cache) Decr(key string) (int64, error)Decr decreases cached int value.
func (*Cache) Delete
func (rc *Cache) Delete(key string) errorDelete file cache value.
func (*Cache) Get
func (rc *Cache) Get(key string) ([]byte, error)Get gets a key's value from memcache.
func (*Cache) GetDefaultConfig
func (rc *Cache) GetDefaultConfig() stringfunc (*Cache) GetMulti
func (rc *Cache) GetMulti(keys []string) ([][]byte, error)GetMulti gets one or keys values from ssdb.
func (*Cache) Has
func (rc *Cache) Has(key string) boolHas checks if value exists.
func (*Cache) Incr
func (rc *Cache) Incr(key string) (int64, error)Incr increases cached int value. fc value is saved forever unless deleted.
func (*Cache) Init
func (rc *Cache) Init() errorInit makes new a dir for file cache if it does not already exist
func (*Cache) Peek
func (rc *Cache) Peek(key string) (any, error)Peek value from file cache. if nonexistent or expired return an empty string.
func (*Cache) PeekMulti
func (rc *Cache) PeekMulti(keys []string) ([]any, error)PeekMulti gets values from file cache. if nonexistent or expired return an empty string.
func (*Cache) Put
func (rc *Cache) Put(key string, val any, ttl time.Duration) errorPut value into file cache. timeout: how long this file should be kept in ms if timeout equals rc.EmbedExpiry(default is 0), cache this item forever.
func (*Cache) PutMulti
func (rc *Cache) PutMulti(values map[string]any, timeout time.Duration) errorfunc (*Cache) Reset
func (rc *Cache) Reset() errorfunc (*Cache) Set
func (rc *Cache) Set(key string, val []byte, ttl time.Duration) errorfunc (*Cache) SetMulti
func (rc *Cache) SetMulti(values map[string][]byte, ttl time.Duration) errorfunc (*Cache) SetName
func (rc *Cache) SetName(name string)func (*Cache) StartAndGC
func (rc *Cache) StartAndGC(configs ...string) errorStartAndGC starts gc for file cache. config must be in the format {cache_path:"/cache","file_suffix":".bin","directory_level":"2","embed_expiry":"0"}
Generated by gomarkdoc