-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91ca2cf
commit cdb0efd
Showing
5 changed files
with
58 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cache // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/coralogixprocessor/internal/cache | ||
|
||
import lru "github.com/hashicorp/golang-lru/v2" | ||
|
||
type lruBlueprintCache[V any] struct { | ||
cache *lru.Cache[uint64, V] | ||
} | ||
|
||
var _ Cache[any] = (*lruBlueprintCache[any])(nil) | ||
|
||
func (c *lruBlueprintCache[V]) Get(hash uint64) (V, bool) { | ||
return c.cache.Get(hash) | ||
} | ||
|
||
func (c *lruBlueprintCache[V]) Add(hash uint64, v V) { | ||
c.cache.Add(hash, v) | ||
} | ||
|
||
func (c *lruBlueprintCache[V]) Delete(hash uint64) { | ||
c.cache.Remove(hash) | ||
} | ||
|
||
func NewLRUBlueprintCache[V any](size int) (Cache[V], error) { | ||
c, err := lru.New[uint64, V](size) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &lruBlueprintCache[V]{cache: c}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cache | ||
|
||
// Cache is a cache using a uint64 as the key and any generic type as the value. | ||
type Cache[V any] interface { | ||
// Get returns the value for the given blueprint hash, and a boolean to indicate whether the hash was found. | ||
// If the hash is not present, the zero value is returned. | ||
Get(hash uint64) (V, bool) | ||
// Add adds the value for a given id | ||
Add(hash uint64, v V) | ||
// Delete deletes the value for the given id | ||
Delete(hash uint64) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters