cache

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IgnoreItems            = "ignore_items"
	ItemNeighbors          = "item_neighbors"
	UserNeighbors          = "user_neighbors"
	CollaborativeRecommend = "collaborative_recommend"
	CTRRecommend           = "ctr_recommend"
	PopularItems           = "popular_items"
	LatestItems            = "latest_items"

	LastModifyItemTime          = "last_modify_item_time"           // the latest timestamp that a user related data was modified
	LastModifyUserTime          = "last_modify_user_time"           // the latest timestamp that an item related data was modified
	LastUpdateUserRecommendTime = "last_update_user_recommend_time" // the latest timestamp that a user's recommendation was updated
	LastUpdateUserNeighborsTime = "last_update_user_neighbors_time" // the latest timestamp that a user's neighbors item was updated
	LastUpdateItemNeighborsTime = "last_update_item_neighbors_time" // the latest timestamp that an item's neighbors was updated

	// GlobalMeta is global meta information
	GlobalMeta              = "global_meta"
	DataImported            = "data_imported"
	LastFitRankingModelTime = "last_fit_match_model_time"
	LastRankingModelVersion = "latest_match_model_version"
)

Variables

View Source
var ErrNoDatabase = fmt.Errorf("no database specified")
View Source
var ErrObjectNotExist = fmt.Errorf("object not exists")

Functions

func RemoveScores

func RemoveScores(items []Scored) []string

RemoveScores resolve items for a slice of ScoredItems.

Types

type Database

type Database interface {
	Close() error
	SetScores(prefix, name string, items []Scored) error
	GetScores(prefix, name string, begin int, end int) ([]Scored, error)
	ClearList(prefix, name string) error
	AppendList(prefix, name string, items ...string) error
	GetList(prefix, name string) ([]string, error)
	GetString(prefix, name string) (string, error)
	SetString(prefix, name string, val string) error
	GetTime(prefix, name string) (time.Time, error)
	SetTime(prefix, name string, val time.Time) error
	GetInt(prefix, name string) (int, error)
	SetInt(prefix, name string, val int) error
	IncrInt(prefix, name string) error
}

Database is the common interface for cache store.

func Open

func Open(path string) (Database, error)

Open a connection to a database.

type NoDatabase

type NoDatabase struct{}

NoDatabase means no database used for cache.

func (NoDatabase) AppendList

func (NoDatabase) AppendList(prefix, name string, items ...string) error

AppendList method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) ClearList

func (NoDatabase) ClearList(prefix, name string) error

ClearList method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) Close

func (NoDatabase) Close() error

Close method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetInt

func (NoDatabase) GetInt(prefix, name string) (int, error)

GetInt method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetList

func (NoDatabase) GetList(prefix, name string) ([]string, error)

GetList method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetScores

func (NoDatabase) GetScores(prefix, name string, begin, end int) ([]Scored, error)

GetScores method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetString

func (NoDatabase) GetString(prefix, name string) (string, error)

GetString method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetTime

func (NoDatabase) GetTime(prefix, name string) (time.Time, error)

GetTime method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) IncrInt

func (NoDatabase) IncrInt(prefix, name string) error

IncrInt method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetInt

func (NoDatabase) SetInt(prefix, name string, val int) error

SetInt method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetScores

func (NoDatabase) SetScores(prefix, name string, items []Scored) error

SetScores method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetString

func (NoDatabase) SetString(prefix, name, val string) error

SetString method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetTime

func (NoDatabase) SetTime(prefix, name string, val time.Time) error

SetTime method of NoDatabase returns ErrNoDatabase.

type Redis

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

Redis cache storage.

func (*Redis) AppendList

func (r *Redis) AppendList(prefix, name string, items ...string) error

AppendList appends a list of scored items to Redis.

func (*Redis) ClearList

func (r *Redis) ClearList(prefix, name string) error

ClearList clears a list of items in Redis.

func (*Redis) Close

func (r *Redis) Close() error

Close redis connection.

func (*Redis) GetInt

func (r *Redis) GetInt(prefix, name string) (int, error)

GetInt returns a integer from Redis.

func (*Redis) GetList

func (r *Redis) GetList(prefix, name string) ([]string, error)

GetList returns a list of scored items from Redis.

func (*Redis) GetScores

func (r *Redis) GetScores(prefix, name string, begin, end int) ([]Scored, error)

GetScores returns a list of scored items from Redis.

func (*Redis) GetString

func (r *Redis) GetString(prefix, name string) (string, error)

GetString returns a string from Redis.

func (*Redis) GetTime

func (r *Redis) GetTime(prefix, name string) (time.Time, error)

GetTime returns a time from Redis.

func (*Redis) IncrInt

func (r *Redis) IncrInt(prefix, name string) error

IncrInt increase a integer in Redis.

func (*Redis) SetInt

func (r *Redis) SetInt(prefix, name string, val int) error

SetInt saves a integer from Redis.

func (*Redis) SetScores

func (r *Redis) SetScores(prefix, name string, items []Scored) error

SetScores save a list of scored items to Redis.

func (*Redis) SetString

func (r *Redis) SetString(prefix, name, val string) error

SetString saves a string to Redis.

func (*Redis) SetTime

func (r *Redis) SetTime(prefix, name string, val time.Time) error

SetTime saves a time from Redis.

type Scored added in v0.2.5

type Scored struct {
	Id    string
	Score float32
}

Scored associate a id with a score.

func CreateScoredItems

func CreateScoredItems(itemIds []string, scores []float32) []Scored

CreateScoredItems from items and scores.

Jump to

Keyboard shortcuts

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