You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The go-cache documentation says you shouldn't access Items() without synchronizing access (which I don't think is possible because the RWLock is private to the cache)
// Returns the items in the cache. This may include items that have expired,
// but have not yet been cleaned up. If this is significant, the Expiration
// fields of the items should be checked. Note that explicit synchronization
// is needed to use a cache and its corresponding Items() return value at
// the same time, as the map is shared.
func (c *cache) Items() map[string]Item
I put up a PR to them to ensure that cache.Items() returns a copy of the map using the synchronized lock while doing so.
Also I added a method GetItem to retrieve a cache Item:
// Get a cache Item from the cache (includes Item.Expiration, Item.Object).
// Returns the item or nil, and a bool indicating
// whether the key was found.
func (c *cache) GetItem(k string) (Item, bool) {
The text was updated successfully, but these errors were encountered:
While testing #17 I ran into an occasional panic in the
store_memory.go
accessing the `cache.Items()[key]The
go-cache
documentation says you shouldn't accessItems()
without synchronizing access (which I don't think is possible because the RWLock is private to the cache)https://github.com/patrickmn/go-cache/blob/master/cache.go#L1001
I put up a PR to them to ensure that
cache.Items()
returns a copy of the map using the synchronized lock while doing so.Also I added a method
GetItem
to retrieve a cacheItem
:https://github.com/dougnukem/go-cache/blob/53c1a5bdb67be8eaf0beee21efdbf7db3bab734a/cache.go#L146
The text was updated successfully, but these errors were encountered: