Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/cache/file_cache

file_cache

go
import "gitlab.soludian.com/soludian/fountain/libs/cache/file_cache"

Index

Constants

go
const DefaultConfig = `{"cache_path":"/cache","file_suffix":".bin","directory_level":"2","embed_expiry":"0"}`

go
const KPackageName = "file_cache"

Variables

FileCache Config

go
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

go
func FileGetContents(filename string) ([]byte, error)

FileGetContents Reads bytes from a file. if non-existent, create this file.

func FilePutContents

go
func FilePutContents(filename string, content []byte) error

FilePutContents puts bytes into a file. if non-existent, create this file.

func GobDecode

go
func GobDecode(data []byte, to *entry) error

GobDecode Gob decodes a file cache item.

func GobEncode

go
func GobEncode(data any) ([]byte, error)

GobEncode Gob encodes a file cache item.

func NewFileCache

go
func NewFileCache() cache.Cache

NewFileCache 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.

go
type Cache struct {
    CachePath      string
    FileSuffix     string
    DirectoryLevel int
    EmbedExpiry    int
    // contains filtered or unexported fields
}

func (*Cache) ClearAll

go
func (rc *Cache) ClearAll(context.Context) error

ClearAll cleans cached files (not implemented)

func (*Cache) Close

go
func (rc *Cache) Close() error

Close the database

func (*Cache) Decr

go
func (rc *Cache) Decr(key string) (int64, error)

Decr decreases cached int value.

func (*Cache) Delete

go
func (rc *Cache) Delete(key string) error

Delete file cache value.

func (*Cache) Get

go
func (rc *Cache) Get(key string) ([]byte, error)

Get gets a key's value from memcache.

func (*Cache) GetDefaultConfig

go
func (rc *Cache) GetDefaultConfig() string

func (*Cache) GetMulti

go
func (rc *Cache) GetMulti(keys []string) ([][]byte, error)

GetMulti gets one or keys values from ssdb.

func (*Cache) Has

go
func (rc *Cache) Has(key string) bool

Has checks if value exists.

func (*Cache) Incr

go
func (rc *Cache) Incr(key string) (int64, error)

Incr increases cached int value. fc value is saved forever unless deleted.

func (*Cache) Init

go
func (rc *Cache) Init() error

Init makes new a dir for file cache if it does not already exist

func (*Cache) Peek

go
func (rc *Cache) Peek(key string) (any, error)

Peek value from file cache. if nonexistent or expired return an empty string.

func (*Cache) PeekMulti

go
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

go
func (rc *Cache) Put(key string, val any, ttl time.Duration) error

Put 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

go
func (rc *Cache) PutMulti(values map[string]any, timeout time.Duration) error

func (*Cache) Reset

go
func (rc *Cache) Reset() error

func (*Cache) Set

go
func (rc *Cache) Set(key string, val []byte, ttl time.Duration) error

func (*Cache) SetMulti

go
func (rc *Cache) SetMulti(values map[string][]byte, ttl time.Duration) error

func (*Cache) SetName

go
func (rc *Cache) SetName(name string)

func (*Cache) StartAndGC

go
func (rc *Cache) StartAndGC(configs ...string) error

StartAndGC 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