Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/cache/memorycache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/cache:go_default_library",
"//pkg/cache/cachemetrics:go_default_library",
"@com_github_hashicorp_golang_lru//:go_default_library",
],
)
Expand Down
9 changes: 9 additions & 0 deletions pkg/cache/memorycache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"sync"

"github.com/pipe-cd/pipe/pkg/cache"
"github.com/pipe-cd/pipe/pkg/cache/cachemetrics"
)

type Cache struct {
Expand All @@ -31,8 +32,16 @@ func NewCache() *Cache {
func (c *Cache) Get(key interface{}) (interface{}, error) {
item, ok := c.values.Load(key)
if !ok {
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelSourceInmemory,
cachemetrics.LabelStatusMiss,
)
return nil, cache.ErrNotFound
}
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelSourceInmemory,
cachemetrics.LabelStatusHit,
)
return item, nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/cache/memorycache/lru_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
lru "github.com/hashicorp/golang-lru"

"github.com/pipe-cd/pipe/pkg/cache"
"github.com/pipe-cd/pipe/pkg/cache/cachemetrics"
)

type LRUCache struct {
Expand All @@ -37,8 +38,16 @@ func NewLRUCache(size int) (*LRUCache, error) {
func (c *LRUCache) Get(key interface{}) (interface{}, error) {
item, ok := c.cache.Get(key)
if !ok {
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelSourceInmemory,
cachemetrics.LabelStatusMiss,
)
return nil, cache.ErrNotFound
}
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelSourceInmemory,
cachemetrics.LabelStatusHit,
)
return item, nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/cache/memorycache/ttl_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/pipe-cd/pipe/pkg/cache"
"github.com/pipe-cd/pipe/pkg/cache/cachemetrics"
)

type entry struct {
Expand Down Expand Up @@ -70,8 +71,16 @@ func (c *TTLCache) evictExpired(t time.Time) {
func (c *TTLCache) Get(key interface{}) (interface{}, error) {
item, ok := c.entries.Load(key)
if !ok {
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelSourceInmemory,
cachemetrics.LabelStatusMiss,
)
return nil, cache.ErrNotFound
}
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelSourceInmemory,
cachemetrics.LabelStatusHit,
)
return item.(*entry).value, nil
}

Expand Down