cache

package
v0.0.0-...-0464d78 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey(s ...string) string

func ReadExtraTTL

func ReadExtraTTL(filename string) error

Types

type APICacheKey

type APICacheKey struct {
	Key      string
	ExtraTTL int64
}
var (
	EMPTY_APIKEY APICacheKey = APICacheKey{Key: "", ExtraTTL: 0}

	ADVANCED_SEARCH APICacheKey = APICacheKey{
		Key: "0", ExtraTTL: 0,
	}

	COMPETITION_STANDING_TABLE APICacheKey = APICacheKey{
		Key: "1", ExtraTTL: 0,
	}

	COMPETITION_WEEKS APICacheKey = APICacheKey{
		Key: "2", ExtraTTL: 0,
	}

	COMPETITIONS_LIST APICacheKey = APICacheKey{
		Key: "3", ExtraTTL: 0,
	}

	MATCH_INFO APICacheKey = APICacheKey{
		Key: "4", ExtraTTL: 0,
	}

	MATCHES_BY_DATE APICacheKey = APICacheKey{
		Key: "5", ExtraTTL: 0,
	}

	MATCHES_BY_WEEKNUMBER APICacheKey = APICacheKey{
		Key: "6", ExtraTTL: 0,
	}

	TRANSFERS APICacheKey = APICacheKey{
		Key: "7", ExtraTTL: 0,
	}

	TRANSFERS_REGIONS APICacheKey = APICacheKey{
		Key: "8", ExtraTTL: 0,
	}

	SEARCH APICacheKey = APICacheKey{
		Key: "9", ExtraTTL: 0,
	}
)

Implemented for kickcore/api package

type Cache

type Cache struct {

	// It's true if you call c.Close()
	Closed bool
	Logger *logging.FileLogger
	// contains filtered or unexported fields
}

func NewCache

func NewCache(d CacheDriver, err error) (*Cache, error)

func (*Cache) CacheFunc

func (c *Cache) CacheFunc(apikey APICacheKey, key string, f func() ([]byte, error)) ([]byte, bool, error)

CacheFunc first tries to returns value from cache, then if key not found in cache, call 'f' and (if it not returned error,) insert returned data into cache

returns (data, data is in cache, error)

func (*Cache) CacheFuncJSON

func (c *Cache) CacheFuncJSON(apikey APICacheKey, key string, f func() (interface{}, error)) ([]byte, bool, error)

Like c.CacheFunc, but recieve interface{} from 'f' and convert it to bytes by json.Marshal.

func (*Cache) Close

func (c *Cache) Close() error

Close the cache

func (*Cache) Delete

func (c *Cache) Delete(apikey APICacheKey, key string) (bool, error)

Delete value specified by the key.

func (*Cache) DeleteMany

func (c *Cache) DeleteMany(key []string) (int64, error)

Delete values which are specified by the keys.

func (*Cache) Insert

func (c *Cache) Insert(apikey APICacheKey, key string, value []byte) (bool, error)

Insert key-value into the cache.

func (*Cache) Len

func (c *Cache) Len() (int64, error)

Cache length

func (*Cache) Ping

func (c *Cache) Ping(timeout time.Duration) error

Ping cache connection

func (*Cache) Select

func (c *Cache) Select(apikey APICacheKey, key string) ([]byte, error)

Select value specified by the key.

type CacheDriver

type CacheDriver interface {
	// Initialize cache
	Init() error

	// Pings cache connection
	PingContext(ctx context.Context) error

	// Inserts key-value to cache
	// Returns false if key is currently in cache
	Insert(key string, value []byte, date int64) (bool, error)

	// Selects the value specified by key in cache.
	Select(key string, value *[]byte) error

	// Selects the keys which are expired.
	SelectExpiredValues(expireAfter int64) ([]string, error)

	// Deletes the value specified by key in cache.
	Delete(key string) (bool, error)

	// Deletes the values which are specified by any key in cache.
	DeleteMany(keys []string) (int64, error)

	// Returns the length of cache
	Len() (int64, error)

	// Closes cache
	Close() error
}

type ExpirationMachine

type ExpirationMachine struct {
	// Cache
	ActiveCache *Cache
	// contains filtered or unexported fields
}

Expiration Machine - deletes values which are expired.

func (*ExpirationMachine) IsStarted

func (e *ExpirationMachine) IsStarted() bool

func (*ExpirationMachine) Start

func (e *ExpirationMachine) Start(interval time.Duration) error

func (*ExpirationMachine) Stop

func (e *ExpirationMachine) Stop() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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