cache

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IgnoreItems            = "ignore_items"            // ignored items for each user
	HiddenItems            = "hidden_items"            // hidden items
	ItemNeighbors          = "item_neighbors"          // neighbors of each item
	UserNeighbors          = "user_neighbors"          // neighbors of each user
	CollaborativeRecommend = "collaborative_recommend" // collaborative filtering recommendation for each user
	OfflineRecommend       = "offline_recommend"       // offline recommendation for each user
	// PopularItems is sorted set of popular items. The format of key:
	//  Global popular items      - latest_items
	//  Categorized popular items - latest_items/{category}
	PopularItems = "popular_items"
	// LatestItems is sorted set of the latest items. The format of key:
	//  Global latest items      - latest_items
	//  Categorized latest items - latest_items/{category}
	LatestItems = "latest_items"
	// ItemCategories is the set of item categories. The format of key:
	//	Global item categories - item_categories
	//	Categories of an item  - item_categories/{item_id}
	ItemCategories = "item_categories"

	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
	LastUpdateLatestItemsTime   = "last_update_latest_items_time"   // the latest timestamp that latest items were updated
	LastUpdatePopularItemsTime  = "last_update_popular_items_time"  // the latest timestamp that popular items were 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 (
	ErrObjectNotExist = errors.NotFoundf("object")
	ErrNoDatabase     = errors.NotAssignedf("database")
)
View Source
var (
	SetScoresSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "cache",
		Name:      "set_scores_seconds",
	})
	GetScoresSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "cache",
		Name:      "get_scores_seconds",
	})
	ClearScoresSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "cache",
		Name:      "clear_scores_seconds",
	})
	AppendScoresSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "cache",
		Name:      "append_scores_seconds",
	})
)

Functions

func Key added in v0.3.1

func Key(keys ...string) string

Key creates key for cache. Empty field will be ignored.

func RemoveScores

func RemoveScores(items []Scored) []string

RemoveScores resolve items for a slice of ScoredItems.

func SortScores added in v0.3.1

func SortScores(scores []Scored)

SortScores sorts scores from high score to low score.

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)
	ClearScores(prefix, name string) error
	AppendScores(prefix, name string, items ...Scored) error
	SetCategoryScores(prefix, name, category string, items []Scored) error
	GetCategoryScores(prefix, name, category string, begin, end int) ([]Scored, 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
	Delete(prefix, name string) error
	Exists(prefix string, names ...string) ([]int, error)

	GetSet(key string) ([]string, error)
	SetSet(key string, members ...string) error
	AddSet(key string, members ...string) error
	RemSet(key string, members ...string) error

	GetSortedScore(key, member string) (float32, error)
	GetSorted(key string, begin, end int) ([]Scored, error)
	SetSorted(key string, scores []Scored) error
	IncrSorted(key, member string) error
	RemSorted(key, member 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) AddSet added in v0.3.1

func (NoDatabase) AddSet(_ string, _ ...string) error

AddSet method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) AppendScores added in v0.2.7

func (NoDatabase) AppendScores(_, _ string, _ ...Scored) error

AppendScores method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) ClearScores added in v0.2.7

func (NoDatabase) ClearScores(_, _ string) error

ClearScores method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) Close

func (NoDatabase) Close() error

Close method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) Delete added in v0.3.1

func (NoDatabase) Delete(_, _ string) error

Delete method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) Exists added in v0.3.1

func (NoDatabase) Exists(_ string, _ ...string) ([]int, error)

Exists method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetCategoryScores added in v0.3.0

func (NoDatabase) GetCategoryScores(_, _, _ string, _, _ int) ([]Scored, error)

GetCategoryScores method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetInt

func (NoDatabase) GetInt(_, _ string) (int, error)

GetInt method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetScores

func (NoDatabase) GetScores(_, _ string, _, _ int) ([]Scored, error)

GetScores method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetSet added in v0.3.1

func (NoDatabase) GetSet(_ string) ([]string, error)

GetSet method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetSorted added in v0.3.1

func (NoDatabase) GetSorted(_ string, _, _ int) ([]Scored, error)

GetSorted method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetSortedScore added in v0.3.1

func (NoDatabase) GetSortedScore(_, _ string) (float32, error)

GetSortedScore method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetString

func (NoDatabase) GetString(_, _ string) (string, error)

GetString method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) GetTime

func (NoDatabase) GetTime(_, _ string) (time.Time, error)

GetTime method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) IncrInt

func (NoDatabase) IncrInt(_, _ string) error

IncrInt method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) IncrSorted added in v0.3.1

func (NoDatabase) IncrSorted(_, _ string) error

IncrSorted method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) RemSet added in v0.3.1

func (NoDatabase) RemSet(_ string, _ ...string) error

RemSet method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) RemSorted added in v0.3.1

func (NoDatabase) RemSorted(_, _ string) error

RemSorted method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetCategoryScores added in v0.3.0

func (NoDatabase) SetCategoryScores(_, _, _ string, _ []Scored) error

SetCategoryScores method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetInt

func (NoDatabase) SetInt(_, _ string, _ int) error

SetInt method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetScores

func (NoDatabase) SetScores(_, _ string, _ []Scored) error

SetScores method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetSet added in v0.3.1

func (NoDatabase) SetSet(_ string, _ ...string) error

SetSet method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetSorted added in v0.3.1

func (NoDatabase) SetSorted(_ string, _ []Scored) error

SetSorted method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetString

func (NoDatabase) SetString(_, _, _ string) error

SetString method of NoDatabase returns ErrNoDatabase.

func (NoDatabase) SetTime

func (NoDatabase) SetTime(_, _ string, _ time.Time) error

SetTime method of NoDatabase returns ErrNoDatabase.

type Redis

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

Redis cache storage.

func (*Redis) AddSet added in v0.3.1

func (r *Redis) AddSet(key string, members ...string) error

AddSet adds members to a set in Redis.

func (*Redis) AppendScores added in v0.2.7

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

AppendScores appends a list of scored items to Redis.

func (*Redis) ClearScores added in v0.2.7

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

ClearScores clears a list of scored items in Redis.

func (*Redis) Close

func (r *Redis) Close() error

Close redis connection.

func (*Redis) Delete added in v0.3.1

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

Delete object from Redis.

func (*Redis) Exists added in v0.3.1

func (r *Redis) Exists(prefix string, names ...string) ([]int, error)

Exists check keys in Redis.

func (*Redis) GetCategoryScores added in v0.3.0

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

GetCategoryScores method of NoDatabase returns ErrNoDatabase.

func (*Redis) GetInt

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

GetInt returns a integer 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) GetSet added in v0.3.1

func (r *Redis) GetSet(key string) ([]string, error)

GetSet returns members of a set from Redis.

func (*Redis) GetSorted added in v0.3.1

func (r *Redis) GetSorted(key string, begin, end int) ([]Scored, error)

GetSorted get scores from sorted set.

func (*Redis) GetSortedScore added in v0.3.1

func (r *Redis) GetSortedScore(key, member string) (float32, error)

GetSortedScore get the score of a member from sorted set.

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) IncrSorted added in v0.3.1

func (r *Redis) IncrSorted(key, member string) error

IncrSorted increase score in sorted set.

func (*Redis) RemSet added in v0.3.1

func (r *Redis) RemSet(key string, members ...string) error

RemSet removes members from a set in Redis.

func (*Redis) RemSorted added in v0.3.1

func (r *Redis) RemSorted(key, member string) error

RemSorted method of NoDatabase returns ErrNoDatabase.

func (*Redis) SetCategoryScores added in v0.3.0

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

SetCategoryScores method of NoDatabase returns ErrNoDatabase.

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) SetSet added in v0.3.1

func (r *Redis) SetSet(key string, members ...string) error

SetSet overrides a set with members in Redis.

func (*Redis) SetSorted added in v0.3.1

func (r *Redis) SetSorted(key string, scores []Scored) error

SetSorted add scores to sorted set.

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