applycache

package
v0.0.0-...-0fffe9f Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsOpenAIEnabled

func IsOpenAIEnabled(indices []string) bool

IsOpenAIEnabled will check if OpenAI is enabled by checking a few things. - If tier allows OpenAI - If cluster has OpenAI enabled - If passed index is whitelisted

Types

type Cache

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

func Instance

func Instance() *Cache

Instance returns the singleton instance of Cache plugin. Note: Only this function must be used (both within and outside the package) to obtain the instance Cache in order to avoid stateless instances of the plugin.

func (*Cache) AlternateRoutes

func (c *Cache) AlternateRoutes() []plugins.Route

Expose plugin specific routes

func (*Cache) CreateDayStat

func (c *Cache) CreateDayStat()

CreateDayStat will create the stat for the day using the dayID generated.

This function should run at 12 AM everyday and will create a stat object with 0 values initialized.

func (*Cache) DeleteOlderRecords

func (c *Cache) DeleteOlderRecords()

DeleteOlderRecords will delete all records that are older than 30 days.

This function will run at midnight everyday and will delete all records that are less than the created unix timestamp.

func (*Cache) ESMiddleware

func (c *Cache) ESMiddleware() []middleware.Middleware

func (*Cache) InitFunc

func (c *Cache) InitFunc() error

InitFunc is a part of Plugin interface that gets executed only once, and initializes the dao, i.e. elasticsearch before the plugin is operational.

func (*Cache) Name

func (f *Cache) Name() string

Name returns the name of the plugin: "applycache"

func (*Cache) RSMiddleware

func (c *Cache) RSMiddleware() []middleware.Middleware

func (*Cache) RollOverJob

func (c *Cache) RollOverJob()

RollOverJob will rollover the stats every 10 minutes.

This function will use the generatedID and use the rolled over stats every 10 minutes. This function assumes that the document is already present in the index with a proper day value set in the document so rollover will only update the stat values.

func (*Cache) Routes

func (c *Cache) Routes() []plugins.Route

func (*Cache) StartJobs

func (c *Cache) StartJobs()

StartJobs will start the cronjobs for applying cache stats

This function will start two jobs: - run every day at 12 AM and create document for day - run every 10 mins and roll over stats - run delete older record job at 12 AM every day

type CacheStatES

type CacheStatES struct {
	Day               int64 `json:"day"`
	CacheRequestCount int64 `json:"cache_request_count"`
	CacheHit          int64 `json:"cache_hit"`
	CacheMiss         int64 `json:"cache_miss"`
	PerformanceSave   int64 `json:"performance_save"`
}

type CachedResponse

type CachedResponse struct {
	Body            []byte
	Headers         map[string]string
	PerformanceSave int64
}

func ApplyCache

func ApplyCache(
	urlPath string,
	rsAPIBody *querytranslate.RSQuery,
	requestBody []byte,
	startTime *time.Time,
	userId string,
	indices []string,
) (*CachedResponse, error)

type RollOverStat

type RollOverStat struct {
	Stat *CacheStatES
	// contains filtered or unexported fields
}

func (*RollOverStat) Add

func (r *RollOverStat) Add(isHit bool, performanceSave int64)

Add will add new stats to the current stat object.

The value of performanceSave will be ignored if the cache was not hit.

func (*RollOverStat) Init

func (r *RollOverStat) Init() *RollOverStat

Init will initiate the RollOverStat value and return a new instance

func (*RollOverStat) RollOver

func (r *RollOverStat) RollOver() *CacheStatES

Rollover will roll over the stats present currently and create an empty container to keep new data.

This function will not take care of rolling over on every n minutes or hours. That should be handled at a top level.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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