Codebase list golang-github-renekroon-ttlcache / 9378e75
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
4 changed file(s) with 43 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
1818 - golint .
1919 - go test -cover -race -count=1 -timeout=30s -run .
2020 - 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
2222 - 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
09 # 2.10.0 (December 2021)
110
211 #62 : @nikhilk1701 found a memory leak where removed items are not directly eligible for garbage collection. There are no API changes.
456456 return keys
457457 }
458458
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
459477 // SetTTL sets the global TTL value for items in the cache, which can be overridden at the item level.
460478 func (cache *Cache) SetTTL(ttl time.Duration) error {
461479 cache.mutex.Lock()
828828 assert.Equal(t, []string{"hello"}, keys, "Expected keys contains 'hello'")
829829 }
830830
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
831846 func TestCacheGetWithTTL(t *testing.T) {
832847 t.Parallel()
833848