Skip to content

Commit

Permalink
🐌 cache json templates
Browse files Browse the repository at this point in the history
🐌 cache json templates
  • Loading branch information
petar-cvit authored Apr 17, 2024
2 parents 3c89496 + 9385ef2 commit 43c14b9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
20 changes: 15 additions & 5 deletions cyclops-ctrl/internal/template/cache/inmemory.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cache

import (
"encoding/json"
"fmt"
"time"

"github.com/dgraph-io/ristretto"
json "github.com/json-iterator/go"

"github.com/cyclops-ui/cycops-ctrl/internal/models"
)
Expand Down Expand Up @@ -35,12 +35,17 @@ func (t Templates) GetTemplate(repo, path, version string) (*models.Template, bo
return nil, false
}

template, ok := value.(models.Template)
data, ok := value.([]byte)
if !ok {
return nil, false
}

return &template, ok
var template *models.Template
if err := json.Unmarshal(data, &template); err != nil {
return nil, false
}

return template, ok
}

func (t Templates) SetTemplate(repo, path, version string, template *models.Template) {
Expand All @@ -49,7 +54,7 @@ func (t Templates) SetTemplate(repo, path, version string, template *models.Temp
return
}

t.cache.SetWithTTL(templateKey(repo, path, version), *template, int64(len(data)), time.Minute*15)
t.cache.SetWithTTL(templateKey(repo, path, version), data, int64(len(data)), time.Minute*15)
t.cache.Wait()
}

Expand All @@ -68,7 +73,12 @@ func (t Templates) GetTemplateInitialValues(repo, path, version string) (map[int
}

func (t Templates) SetTemplateInitialValues(repo, path, version string, values map[interface{}]interface{}) {
t.cache.SetWithTTL(initialValuesKey(repo, path, version), values, int64(len(values)), time.Minute*15)
data, err := json.Marshal(values)
if err != nil {
return
}

t.cache.SetWithTTL(initialValuesKey(repo, path, version), values, int64(len(data)), time.Minute*15)
t.cache.Wait()
}

Expand Down
4 changes: 2 additions & 2 deletions cyclops-ctrl/internal/template/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"io"
path2 "path"
"path/filepath"
Expand All @@ -17,8 +19,6 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"helm.sh/helm/v3/pkg/chart"

"github.com/cyclops-ui/cycops-ctrl/internal/auth"
Expand Down
4 changes: 2 additions & 2 deletions install/cyclops-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ spec:
spec:
containers:
- name: cyclops-ui
image: cyclopsui/cyclops-ui:v0.3.1
image: cyclopsui/cyclops-ui:v0.3.2-rc.3
ports:
- containerPort: 80
env:
Expand Down Expand Up @@ -430,7 +430,7 @@ spec:
serviceAccountName: cyclops-ctrl
containers:
- name: cyclops-ctrl
image: cyclopsui/cyclops-ctrl:v0.3.1
image: cyclopsui/cyclops-ctrl:v0.3.2-rc.3
ports:
- containerPort: 8080
env:
Expand Down

0 comments on commit 43c14b9

Please sign in to comment.