summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/hashicorp/golang-lru
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-05-24 00:06:21 +0200
committerGitHub <noreply@github.com>2020-05-24 00:06:21 +0200
commit393f9e998b1b40aa59d3fb8794c3a73da38c3fb7 (patch)
tree2bc9b6e6abdbdc6d811b155997597bdae62bc7db /vendor/github.com/hashicorp/golang-lru
parentba0bfe70a8f07164e1341f4b094841acdad5c3a2 (diff)
downloadmatterbridge-msglm-393f9e998b1b40aa59d3fb8794c3a73da38c3fb7.tar.gz
matterbridge-msglm-393f9e998b1b40aa59d3fb8794c3a73da38c3fb7.tar.bz2
matterbridge-msglm-393f9e998b1b40aa59d3fb8794c3a73da38c3fb7.zip
Update dependencies / vendor (#1146)
Diffstat (limited to 'vendor/github.com/hashicorp/golang-lru')
-rw-r--r--vendor/github.com/hashicorp/golang-lru/lru.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/vendor/github.com/hashicorp/golang-lru/lru.go b/vendor/github.com/hashicorp/golang-lru/lru.go
index 052a38b4..4e5e9d8f 100644
--- a/vendor/github.com/hashicorp/golang-lru/lru.go
+++ b/vendor/github.com/hashicorp/golang-lru/lru.go
@@ -37,7 +37,7 @@ func (c *Cache) Purge() {
c.lock.Unlock()
}
-// Add adds a value to the cache. Returns true if an eviction occurred.
+// Add adds a value to the cache. Returns true if an eviction occurred.
func (c *Cache) Add(key, value interface{}) (evicted bool) {
c.lock.Lock()
evicted = c.lru.Add(key, value)
@@ -71,8 +71,8 @@ func (c *Cache) Peek(key interface{}) (value interface{}, ok bool) {
return value, ok
}
-// ContainsOrAdd checks if a key is in the cache without updating the
-// recent-ness or deleting it for being stale, and if not, adds the value.
+// ContainsOrAdd checks if a key is in the cache without updating the
+// recent-ness or deleting it for being stale, and if not, adds the value.
// Returns whether found and whether an eviction occurred.
func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool) {
c.lock.Lock()
@@ -85,6 +85,22 @@ func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool) {
return false, evicted
}
+// PeekOrAdd checks if a key is in the cache without updating the
+// recent-ness or deleting it for being stale, and if not, adds the value.
+// Returns whether found and whether an eviction occurred.
+func (c *Cache) PeekOrAdd(key, value interface{}) (previous interface{}, ok, evicted bool) {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ previous, ok = c.lru.Peek(key)
+ if ok {
+ return previous, true, false
+ }
+
+ evicted = c.lru.Add(key, value)
+ return nil, false, evicted
+}
+
// Remove removes the provided key from the cache.
func (c *Cache) Remove(key interface{}) (present bool) {
c.lock.Lock()