refactor(storage): Remove decommissioned path for memory store (#313)
This commit is contained in:
2
vendor/github.com/TwiN/gocache/v2/LICENSE.md
generated
vendored
2
vendor/github.com/TwiN/gocache/v2/LICENSE.md
generated
vendored
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 TwiN
|
||||
Copyright (c) 2022 TwiN
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
53
vendor/github.com/TwiN/gocache/v2/README.md
generated
vendored
53
vendor/github.com/TwiN/gocache/v2/README.md
generated
vendored
@ -1,9 +1,9 @@
|
||||
# gocache
|
||||

|
||||

|
||||
[](https://goreportcard.com/report/github.com/TwiN/gocache)
|
||||
[](https://codecov.io/gh/TwiN/gocache)
|
||||
[](https://github.com/TwiN/gocache)
|
||||
[](https://pkg.go.dev/github.com/TwiN/gocache)
|
||||
[](https://pkg.go.dev/github.com/TwiN/gocache/v2)
|
||||
[](https://github.com/TwiN)
|
||||
|
||||
gocache is an easy-to-use, high-performance, lightweight and thread-safe (goroutine-safe) in-memory key-value cache
|
||||
@ -65,27 +65,28 @@ cache.StartJanitor()
|
||||
```
|
||||
|
||||
### Functions
|
||||
| Function | Description |
|
||||
| --------------------------------- | ----------- |
|
||||
| WithMaxSize | Sets the max size of the cache. `gocache.NoMaxSize` means there is no limit. If not set, the default max size is `gocache.DefaultMaxSize`.
|
||||
| WithMaxMemoryUsage | Sets the max memory usage of the cache. `gocache.NoMaxMemoryUsage` means there is no limit. The default behavior is to not evict based on memory usage.
|
||||
| WithEvictionPolicy | Sets the eviction algorithm to be used when the cache reaches the max size. If not set, the default eviction policy is `gocache.FirstInFirstOut` (FIFO).
|
||||
| WithForceNilInterfaceOnNilPointer | Configures whether values with a nil pointer passed to write functions should be forcefully set to nil. Defaults to true.
|
||||
| StartJanitor | Starts the janitor, which is in charge of deleting expired cache entries in the background.
|
||||
| StopJanitor | Stops the janitor.
|
||||
| Set | Same as `SetWithTTL`, but with no expiration (`gocache.NoExpiration`)
|
||||
| SetAll | Same as `Set`, but in bulk
|
||||
| SetWithTTL | Creates or updates a cache entry with the given key, value and expiration time. If the max size after the aforementioned operation is above the configured max size, the tail will be evicted. Depending on the eviction policy, the tail is defined as the oldest
|
||||
| Get | Gets a cache entry by its key.
|
||||
| GetByKeys | Gets a map of entries by their keys. The resulting map will contain all keys, even if some of the keys in the slice passed as parameter were not present in the cache.
|
||||
| GetAll | Gets all cache entries.
|
||||
| GetKeysByPattern | Retrieves a slice of keys that matches a given pattern.
|
||||
| Delete | Removes a key from the cache.
|
||||
| DeleteAll | Removes multiple keys from the cache.
|
||||
| Count | Gets the size of the cache. This includes cache keys which may have already expired, but have not been removed yet.
|
||||
| Clear | Wipes the cache.
|
||||
| TTL | Gets the time until a cache key expires.
|
||||
| Expire | Sets the expiration time of an existing cache key.
|
||||
| Function | Description |
|
||||
|-----------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| WithMaxSize | Sets the max size of the cache. `gocache.NoMaxSize` means there is no limit. If not set, the default max size is `gocache.DefaultMaxSize`. |
|
||||
| WithMaxMemoryUsage | Sets the max memory usage of the cache. `gocache.NoMaxMemoryUsage` means there is no limit. The default behavior is to not evict based on memory usage. |
|
||||
| WithEvictionPolicy | Sets the eviction algorithm to be used when the cache reaches the max size. If not set, the default eviction policy is `gocache.FirstInFirstOut` (FIFO). |
|
||||
| WithForceNilInterfaceOnNilPointer | Configures whether values with a nil pointer passed to write functions should be forcefully set to nil. Defaults to true. |
|
||||
| StartJanitor | Starts the janitor, which is in charge of deleting expired cache entries in the background. |
|
||||
| StopJanitor | Stops the janitor. |
|
||||
| Set | Same as `SetWithTTL`, but with no expiration (`gocache.NoExpiration`) |
|
||||
| SetAll | Same as `Set`, but in bulk |
|
||||
| SetWithTTL | Creates or updates a cache entry with the given key, value and expiration time. If the max size after the aforementioned operation is above the configured max size, the tail will be evicted. Depending on the eviction policy, the tail is defined as the oldest |
|
||||
| Get | Gets a cache entry by its key. |
|
||||
| GetByKeys | Gets a map of entries by their keys. The resulting map will contain all keys, even if some of the keys in the slice passed as parameter were not present in the cache. |
|
||||
| GetAll | Gets all cache entries. |
|
||||
| GetKeysByPattern | Retrieves a slice of keys that matches a given pattern. |
|
||||
| Delete | Removes a key from the cache. |
|
||||
| DeleteAll | Removes multiple keys from the cache. |
|
||||
| DeleteKeysByPattern | Removes all keys that that matches a given pattern. |
|
||||
| Count | Gets the size of the cache. This includes cache keys which may have already expired, but have not been removed yet. |
|
||||
| Clear | Wipes the cache. |
|
||||
| TTL | Gets the time until a cache key expires. |
|
||||
| Expire | Sets the expiration time of an existing cache key. |
|
||||
|
||||
For further documentation, please refer to [Go Reference](https://pkg.go.dev/github.com/TwiN/gocache)
|
||||
|
||||
@ -132,7 +133,7 @@ func main() {
|
||||
cache.SetWithTTL("key-with-ttl", "value", 60*time.Minute)
|
||||
cache.SetAll(map[string]interface{}{"k1": "v1", "k2": "v2", "k3": "v3"})
|
||||
|
||||
fmt.Println("[Count] Cache size:", cache.Count())
|
||||
fmt.Println("[Count] Cache size:", cache.Count())
|
||||
|
||||
value, exists := cache.Get("key")
|
||||
fmt.Printf("[Get] key=key; value=%s; exists=%v\n", value, exists)
|
||||
@ -345,8 +346,8 @@ import (
|
||||
var cache = gocache.NewCache()
|
||||
|
||||
func main() {
|
||||
data := retrieveCacheEntriesUsingWhateverMeanYouUsedToPersistIt()
|
||||
cache.SetAll(data)
|
||||
data := retrieveCacheEntriesUsingWhateverMeanYouUsedToPersistIt()
|
||||
cache.SetAll(data)
|
||||
// Start everything else on another goroutine to prevent blocking the main goroutine
|
||||
go Start()
|
||||
// Wait for termination signal
|
||||
|
12
vendor/github.com/TwiN/gocache/v2/gocache.go
generated
vendored
12
vendor/github.com/TwiN/gocache/v2/gocache.go
generated
vendored
@ -311,8 +311,8 @@ func (cache *Cache) Get(key string) (interface{}, bool) {
|
||||
cache.mutex.Lock()
|
||||
entry, ok := cache.get(key)
|
||||
if !ok {
|
||||
cache.mutex.Unlock()
|
||||
cache.stats.Misses++
|
||||
cache.mutex.Unlock()
|
||||
return nil, false
|
||||
}
|
||||
if entry.Expired() {
|
||||
@ -388,8 +388,7 @@ func (cache *Cache) GetAll() map[string]interface{} {
|
||||
// cache.GetKeysByPattern("*some*", 0) will return all keys containing "some" in them
|
||||
// cache.GetKeysByPattern("*some*", 5) will return 5 keys (or less) containing "some" in them
|
||||
//
|
||||
// Note that GetKeysByPattern does not trigger active evictions, nor does it count as accessing the entry, the latter
|
||||
// only applying if the cache uses the LeastRecentlyUsed eviction policy.
|
||||
// Note that GetKeysByPattern does not trigger active evictions, nor does it count as accessing the entry (if LRU).
|
||||
// The reason for that behavior is that these two (active eviction and access) only applies when you access the value
|
||||
// of the cache entry, and this function only returns the keys.
|
||||
func (cache *Cache) GetKeysByPattern(pattern string, limit int) []string {
|
||||
@ -435,6 +434,13 @@ func (cache *Cache) DeleteAll(keys []string) int {
|
||||
return numberOfKeysDeleted
|
||||
}
|
||||
|
||||
// DeleteKeysByPattern deletes all entries matching a given key pattern and returns the number of entries deleted.
|
||||
//
|
||||
// Note that DeleteKeysByPattern does not trigger active evictions, nor does it count as accessing the entry (if LRU).
|
||||
func (cache *Cache) DeleteKeysByPattern(pattern string) int {
|
||||
return cache.DeleteAll(cache.GetKeysByPattern(pattern, 0))
|
||||
}
|
||||
|
||||
// Count returns the total amount of entries in the cache, regardless of whether they're expired or not
|
||||
func (cache *Cache) Count() int {
|
||||
cache.mutex.RLock()
|
||||
|
Reference in New Issue
Block a user