cache

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TopicCacheKey is used to cache the topics
	TopicCacheKey = "root-topic-cache"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List struct {
	Topic *TopicCache
}

CacheList is a list of caches for the dp-search-data-extractor

func GetMockCacheList

func GetMockCacheList(ctx context.Context) (*List, error)

GetMockCacheList returns a mocked list of cache which contains the topic cache

type Subtopic

type Subtopic struct {
	ID              string
	LocaliseKeyName string
	Slug            string
	ReleaseDate     *time.Time
	// This is a reference to the parent topic
	ParentID   string
	ParentSlug string
}

Subtopic represents the data which is cached for a subtopic to be used by the dp-search-data-extractor

type Subtopics

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

Subtopics contains a list of subtopics in map form with addition to mutex locking The subtopicsMap is used to keep a record of subtopics to be later used to generate the subtopics id `query` for a topic and to check if the subtopic id given by a user exists

func NewSubTopicsMap

func NewSubTopicsMap() *Subtopics

GetNewSubTopicsMap creates a new subtopics id map to store subtopic ids with addition to mutex locking

func (*Subtopics) AppendSubtopicID

func (sts *Subtopics) AppendSubtopicID(id string, subtopic Subtopic)

AppendSubtopicID appends the subtopic id to the map stored in SubtopicsIDs with consideration to mutex locking

func (*Subtopics) CheckTopicIDExists

func (sts *Subtopics) CheckTopicIDExists(key string) bool

CheckTopicIDExists returns subtopic for given key (id)

func (*Subtopics) Get

func (sts *Subtopics) Get(key string) (Subtopic, bool)

Get returns subtopic for given key (id)

func (*Subtopics) GetSubtopics

func (sts *Subtopics) GetSubtopics() (subtopics []Subtopic)

GetSubtopics returns an array of subtopics

func (*Subtopics) GetSubtopicsIDsQuery

func (sts *Subtopics) GetSubtopicsIDsQuery() string

GetSubtopicsIDsQuery gets the subtopics ID query for a topic

type Topic

type Topic struct {
	ID              string
	LocaliseKeyName string
	Slug            string
	ReleaseDate     *time.Time
	// Query is a comma separated string of topic id and its subtopic ids which will be used by the application to create the query
	Query string
	// List is a map[string]Subtopics which contains the topic id and a list of it's subtopics
	List *Subtopics
}

Topic represents the data which is cached for a topic to be used by the dp-search-data-extractor

func GetEmptyTopic

func GetEmptyTopic() *Topic

GetEmptyTopic returns an empty topic cache e.g in an event where updating the cache of the topic fails

func GetMockRootTopic

func GetMockRootTopic(rootTopicID string) *Topic

GetMockRootTopic returns the mocked root topic

type TopicCache

type TopicCache struct {
	*dpcache.Cache
}

TopicCache is a wrapper to dpcache.Cache which has additional fields and methods specifically for caching topics

func NewTopicCache

func NewTopicCache(ctx context.Context, updateInterval *time.Duration) (*TopicCache, error)

NewTopicCache create a topic cache object to be used in the service which will update at every updateInterval If updateInterval is nil, this means that the cache will only be updated once at the start of the service

func (*TopicCache) AddUpdateFunc

func (tc *TopicCache) AddUpdateFunc(title string, updateFunc func() *Topic)

AddUpdateFunc adds an update function to the topic cache for a topic with the `title` passed to the function This update function will then be triggered once or at every fixed interval as per the prior setup of the TopicCache

func (*TopicCache) GetData

func (tc *TopicCache) GetData(ctx context.Context, key string) (*Topic, error)

GetData returns the topic cache requested by key and returns an empty topic if not found, not of the cache interface type or nil.

func (*TopicCache) GetTopic

func (tc *TopicCache) GetTopic(ctx context.Context, slug string) (*Subtopic, error)

func (*TopicCache) GetTopicCacheKey

func (tc *TopicCache) GetTopicCacheKey() string

GetTopicCacheKey gets the constant value set for the root topic cache key

func (*TopicCache) GetTopicFromSubtopic

func (tc *TopicCache) GetTopicFromSubtopic(subtopic *Subtopic) *Topic

GetTopicFromSubtopic returns an empty topic cache in the event when updating the cache of the topic fails

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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