Update upstream source from tag 'upstream/11.0+ds'
Update to upstream version '11.0+ds'
with Debian dir db2a0b0bcec5487d7cd56077f010b58085c458da
Sascha Steinbiss
2 years ago
18 | 18 |
- golint .
|
19 | 19 |
- go test -cover -race -count=1 -timeout=30s -run .
|
20 | 20 |
- go test -covermode=count -coverprofile=coverage.out -timeout=90s -run .
|
21 | |
- if [ "$TRAVIS_BRANCH" = "master" ]; then $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN; fi
|
|
21 |
- if test ! -z "$COVERALLS_TOKEN"; then $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN; fi
|
22 | 22 |
- cd bench; go test -run=Bench.* -bench=. -benchmem; cd ..⏎
|
|
0 |
# 2.11.0 (December 2021)
|
|
1 |
|
|
2 |
#64: @DoubeDi added a method `GetItems` to retrieve all items in the cache. This method also triggers all callbacks associated with a normal `Get`
|
|
3 |
|
|
4 |
## API changes:
|
|
5 |
|
|
6 |
// GetItems returns a copy of all items in the cache. Returns nil when the cache has been closed.
|
|
7 |
func (cache *Cache) GetItems() map[string]interface{} {
|
|
8 |
|
0 | 9 |
# 2.10.0 (December 2021)
|
1 | 10 |
|
2 | 11 |
#62 : @nikhilk1701 found a memory leak where removed items are not directly eligible for garbage collection. There are no API changes.
|
456 | 456 |
return keys
|
457 | 457 |
}
|
458 | 458 |
|
|
459 |
// GetItems returns a copy of all items in the cache. Returns nil when the cache has been closed.
|
|
460 |
func (cache *Cache) GetItems() map[string]interface{} {
|
|
461 |
cache.mutex.Lock()
|
|
462 |
defer cache.mutex.Unlock()
|
|
463 |
|
|
464 |
if cache.isShutDown {
|
|
465 |
return nil
|
|
466 |
}
|
|
467 |
items := make(map[string]interface{}, len(cache.items))
|
|
468 |
for k := range cache.items {
|
|
469 |
item, exists, _ := cache.getItem(k)
|
|
470 |
if exists {
|
|
471 |
items[k] = item.data
|
|
472 |
}
|
|
473 |
}
|
|
474 |
return items
|
|
475 |
}
|
|
476 |
|
459 | 477 |
// SetTTL sets the global TTL value for items in the cache, which can be overridden at the item level.
|
460 | 478 |
func (cache *Cache) SetTTL(ttl time.Duration) error {
|
461 | 479 |
cache.mutex.Lock()
|
828 | 828 |
assert.Equal(t, []string{"hello"}, keys, "Expected keys contains 'hello'")
|
829 | 829 |
}
|
830 | 830 |
|
|
831 |
func TestCacheGetItems(t *testing.T) {
|
|
832 |
t.Parallel()
|
|
833 |
|
|
834 |
cache := NewCache()
|
|
835 |
defer cache.Close()
|
|
836 |
|
|
837 |
items := cache.GetItems()
|
|
838 |
assert.Empty(t, items, "Expected items to be empty")
|
|
839 |
|
|
840 |
cache.Set("hello", "world")
|
|
841 |
items = cache.GetItems()
|
|
842 |
assert.NotEmpty(t, items, "Expected items to be not empty")
|
|
843 |
assert.Equal(t, map[string]interface{}{"hello": "world"}, items, "Expected items to {'hello': 'world'}")
|
|
844 |
}
|
|
845 |
|
831 | 846 |
func TestCacheGetWithTTL(t *testing.T) {
|
832 | 847 |
t.Parallel()
|
833 | 848 |
|