cache

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package cache a low-level key/value store in pure Go

Index

Constants

This section is empty.

Variables

View Source
var (
	// CachePath the default db path
	CachePath = "cache"

	// ErrKeyNotFound not found the key
	ErrKeyNotFound = errors.New("key not found")
)

Functions

func NewCache

func NewCache(opt Options) (cloudcat.Cache, error)

NewCache returns a new Cache that will store items in bolt.DB.

func NewCookie

func NewCookie(opt Options) (cloudcat.Cookie, error)

NewCookie returns a new Cookie that will store cookies in bolt.DB.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is an implementation of Cache that stores bytes in bolt.DB.

func (*Cache) Del

func (c *Cache) Del(key string)

Del removes key from the cache.

func (*Cache) Get

func (c *Cache) Get(key string) (value []byte, ok bool)

Get returns the []byte and true, if not existing returns false.

func (*Cache) Set

func (c *Cache) Set(key string, value []byte)

Set saves []byte to the cache with key.

func (*Cache) SetWithTimeout

func (c *Cache) SetWithTimeout(key string, value []byte, timeout time.Duration)

SetWithTimeout saves []byte to the cache with key and timeout.

type Cookie struct {
	// contains filtered or unexported fields
}

Cookie is an implementation of cache.Cookie that stores http.Cookie in bolt.DB.

func (*Cookie) CookieString

func (c *Cookie) CookieString(u *url.URL) []string

CookieString returns the cookies string for the given URL.

func (*Cookie) Cookies

func (c *Cookie) Cookies(u *url.URL) []*http.Cookie

Cookies returns the cookies to send in a request for the given URL.

func (*Cookie) DeleteCookie

func (c *Cookie) DeleteCookie(u *url.URL)

DeleteCookie delete the cookies for the given URL.

func (*Cookie) SetCookies

func (c *Cookie) SetCookies(u *url.URL, cookies []*http.Cookie)

SetCookies handles the receipt of the cookies in a reply for the given URL.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB a bbolt.DB instance

func NewDB

func NewDB(path, name string, interval time.Duration) (*DB, error)

NewDB creates a new DB instance if interval above 0, will not clear expired keys

func (*DB) Close

func (db *DB) Close() error

Close closes the database.

func (*DB) Delete

func (db *DB) Delete(key []byte) error

Delete a specified key from DB.

func (*DB) DeleteBatch

func (db *DB) DeleteBatch(keys [][]byte) error

DeleteBatch delete data in batch.

func (*DB) Get

func (db *DB) Get(key []byte) (value []byte, err error)

Get reads the value from the bucket with key.

func (*DB) Put

func (db *DB) Put(key, value []byte) (err error)

Put method writes kv according to the bucket.

func (*DB) PutWithTimeout

func (db *DB) PutWithTimeout(key, value []byte, timeout time.Duration) (err error)

PutWithTimeout method writes kv with timeout according to the bucket.

type Options

type Options struct {
	Path                string        `yaml:"path"`
	ExpireCleanInterval time.Duration `yaml:"expire-clean-interval"`
}

Options the cache configuration

Jump to

Keyboard shortcuts

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