cache

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: 35 Imported by: 0

Documentation

Index

Constants

View Source
const CachedRequestHeader = "X-request-Cache"

Variables

This section is empty.

Functions

func GetCacheKey

func GetCacheKey(url string, body []byte) string

Cache key is prefixed by request url to avoid conflicts among same requests for different indices

func GetSearchCache

func GetSearchCache() *ristretto.Cache

func ReadResponseFromCache

func ReadResponseFromCache(url string, body []byte) (string, []byte)

func RecordRequest

func RecordRequest(urlPath string, rsAPIBody *querytranslate.RSQuery, reqBody []byte, response []byte)

This handler writes to request cache

func ShouldApplyCache

func ShouldApplyCache(req *http.Request, requestBody querytranslate.RSQuery) bool

Apply response from cache 1. if `useCache` value is set to `true` (Highest priority, ignores the cache preference) 2. validate cache preferences

func UpdateValueWithAIAnswer

func UpdateValueWithAIAnswer(cacheKey string, queryId string, aiAnswerResponse []byte, response *openai.InternalChatGPTResponse, olderValue []byte, maxDuration int64, cost int64)

UpdateValueWithAIAnswer will inject the AIAnswer response into the cached response object

func ValidateCachePreferences

func ValidateCachePreferences(req *http.Request) bool

Types

type Cache

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

func Instance

func Instance() *Cache

Instance returns the singleton instace 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) 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: "cache"

func (*Cache) RSMiddleware

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

func (*Cache) Routes

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

type CacheConfig

type CacheConfig struct {
	EnableCache *bool `json:"enable_cache,omitempty"`
	// MaxSize represents the size limit for request cache
	// It should be in MB(s)
	MaxSize *int64 `json:"max_size,omitempty"`
	// MaxDuration represents the TTL(time to live) for a particular request
	// It should be in seconds
	MaxDuration *int64 `json:"max_duration,omitempty"`
	// Represents the indices to be cached
	Indices *[]string `json:"indices,omitempty"`
	// Represents external cache URL
	Addr *string `json:"addr,omitempty"`
	// Password
	Password *string `json:"password,omitempty"`
	// Database
	Database *int `json:"database,omitempty"`
}

func GetCachePreferences

func GetCachePreferences() CacheConfig

To get cache preferences

type CacheSyncScript

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

func (CacheSyncScript) Index

func (s CacheSyncScript) Index() string

func (CacheSyncScript) PluginName

func (s CacheSyncScript) PluginName() string

func (CacheSyncScript) SetCache

func (s CacheSyncScript) SetCache(response *elastic.SearchResult) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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