Documentation
¶
Index ¶
- Constants
- func GetCacheKey(url string, body []byte) string
- func GetSearchCache() *ristretto.Cache
- func ReadResponseFromCache(url string, body []byte) (string, []byte)
- func RecordRequest(urlPath string, rsAPIBody *querytranslate.RSQuery, reqBody []byte, ...)
- func SanitizeRequest(req querytranslate.RSQuery) querytranslate.RSQuery
- func ShouldApplyCache(req *http.Request, requestBody querytranslate.RSQuery) bool
- func UpdateValueWithAIAnswer(cacheKey string, queryId string, aiAnswerResponse []byte, ...)
- func ValidateCachePreferences(req *http.Request) bool
- type Cache
- type CacheConfig
- type CacheSyncScript
Constants ¶
const CachedRequestHeader = "X-request-Cache"
Variables ¶
This section is empty.
Functions ¶
func GetCacheKey ¶
Cache key is prefixed by request url to avoid conflicts among same requests for different indices
func GetSearchCache ¶
func RecordRequest ¶
func RecordRequest(urlPath string, rsAPIBody *querytranslate.RSQuery, reqBody []byte, response []byte)
This handler writes to request cache
func SanitizeRequest ¶
func SanitizeRequest(req querytranslate.RSQuery) querytranslate.RSQuery
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
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 ¶
Expose plugin specific routes
func (*Cache) ESMiddleware ¶
func (c *Cache) ESMiddleware() []middleware.Middleware
func (*Cache) InitFunc ¶
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) RSMiddleware ¶
func (c *Cache) RSMiddleware() []middleware.Middleware
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"`
}
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