-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repository): cache engine-relevant methods
- Loading branch information
Showing
4 changed files
with
71 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cache | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/hashicorp/golang-lru/v2/expirable" | ||
) | ||
|
||
type Cacheable interface { | ||
// Set sets a value in the cache with the given key | ||
Set(key string, value interface{}) | ||
|
||
// Get gets a value from the cache with the given key | ||
Get(key string) (interface{}, bool) | ||
} | ||
|
||
type Cache struct { | ||
cache *expirable.LRU[string, interface{}] | ||
} | ||
|
||
func (c *Cache) Set(key string, value interface{}) { | ||
c.cache.Add(key, value) | ||
} | ||
|
||
func (c *Cache) Get(key string) (interface{}, bool) { | ||
return c.cache.Get(key) | ||
} | ||
|
||
func New() *Cache { | ||
return &Cache{ | ||
cache: expirable.NewLRU[string, interface{}](512, nil, time.Minute*1), | ||
} | ||
} |
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
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
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