mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-16 23:32:29 +00:00
feat: caching (#439)
* feat: added the ability to set a user default AI provider Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * feat: added the ability to set a user default AI provider Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * feat: s3 based caching Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * feat: s3 based caching Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * updated README.md Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * update README.md Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * updated README.md Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * chore: region is a must have Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * chore: clarified remove command * updated remove.go Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * chore: test fmt causing issues will open another pr Signed-off-by: Alex Jones <alexsimonjones@gmail.com> --------- Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
29
pkg/cache/cache.go
vendored
29
pkg/cache/cache.go
vendored
@@ -1,14 +1,41 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type ICache interface {
|
||||
Store(key string, data string) error
|
||||
Load(key string) (string, error)
|
||||
List() ([]string, error)
|
||||
Exists(key string) bool
|
||||
IsCacheDisabled() bool
|
||||
}
|
||||
|
||||
func New(noCache bool) ICache {
|
||||
func New(noCache bool, remoteCache bool) ICache {
|
||||
if remoteCache {
|
||||
return NewS3Cache(noCache)
|
||||
}
|
||||
return &FileBasedCache{
|
||||
noCache: noCache,
|
||||
}
|
||||
}
|
||||
|
||||
// CacheProvider is the configuration for the cache provider when using a remote cache
|
||||
type CacheProvider struct {
|
||||
BucketName string `mapstructure:"bucketname"`
|
||||
Region string `mapstructure:"region"`
|
||||
}
|
||||
|
||||
func RemoteCacheEnabled() (bool, error) {
|
||||
// load remote cache if it is configured
|
||||
var cache CacheProvider
|
||||
err := viper.UnmarshalKey("cache", &cache)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if cache.BucketName != "" && cache.Region != "" {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user