cachefile

package
v1.69.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cache = sync.OnceValue(func() *CacheFile {
	options := bbolt.Options{Timeout: time.Second}
	db, err := bbolt.Open(C.Path.Cache(), fileMode, &options)
	switch err {
	case errors.ErrInvalid, errors.ErrChecksum, errors.ErrVersionMismatch:
		if err = os.Remove(C.Path.Cache()); err != nil {
			log.Warn().Err(err).Msg("[CacheFile] remove invalid cache file failed")
			break
		}
		log.Info().Msg("[CacheFile] remove invalid cache file and create new one")
		db, err = bbolt.Open(C.Path.Cache(), fileMode, &options)
	}
	if err != nil {
		log.Warn().Err(err).Msg("[CacheFile] open cache file failed")
	}

	return &CacheFile{
		DB:              db,
		bucketFakeipKey: []byte("fakeip"),
	}
})

Cache return singleton of CacheFile

Functions

This section is empty.

Types

type CacheFile

type CacheFile struct {
	DB *bbolt.DB
	// contains filtered or unexported fields
}

CacheFile store and update the cache file

func (*CacheFile) Close

func (c *CacheFile) Close() error

func (*CacheFile) DelFakeipPair

func (c *CacheFile) DelFakeipPair(ip, host []byte) error

func (*CacheFile) FlushFakeIP

func (c *CacheFile) FlushFakeIP() error

func (*CacheFile) GetFakeip

func (c *CacheFile) GetFakeip(key []byte) []byte

func (*CacheFile) GetSubscription

func (c *CacheFile) GetSubscription(key string) string

func (*CacheFile) PutFakeip

func (c *CacheFile) PutFakeip(key, value []byte) error

func (*CacheFile) SelectedMap

func (c *CacheFile) SelectedMap() map[string]string

func (*CacheFile) SetBucketFakeipKey added in v1.69.0

func (c *CacheFile) SetBucketFakeipKey(key string)

func (*CacheFile) SetSelected

func (c *CacheFile) SetSelected(group, selected string)

func (*CacheFile) SetSubscription

func (c *CacheFile) SetSubscription(key, value string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL