allegro / bigcache

Efficient cache for gigabytes of data written in Go.
http://allegro.tech/2016/03/writing-fast-cache-service-in-go.html
Apache License 2.0
7.45k stars 593 forks source link

Unused parameter in shards.go [ DEL ] #399

Closed yasharthdubey closed 1 month ago

yasharthdubey commented 2 months ago

The key parameter in the shards.go is not being used here


func (s *cacheShard) del(key string, hashedKey uint64) error {
    // Optimistic pre-check using only readlock
    s.lock.RLock()
    itemIndex := s.hashmap[hashedKey]

    if itemIndex == 0 {
        s.lock.RUnlock()
        s.delmiss()
        return ErrEntryNotFound
    }

    if err := s.entries.CheckGet(int(itemIndex)); err != nil {
        s.lock.RUnlock()
        s.delmiss()
        return err
    }
    s.lock.RUnlock()

    s.lock.Lock()
    {
        // After obtaining the writelock, we need to read the same again,
        // since the data delivered earlier may be stale now
        itemIndex = s.hashmap[hashedKey]

        if itemIndex == 0 {
            s.lock.Unlock()
            s.delmiss()
            return ErrEntryNotFound
        }

        wrappedEntry, err := s.entries.Get(int(itemIndex))
        if err != nil {
            s.lock.Unlock()
            s.delmiss()
            return err
        }

        delete(s.hashmap, hashedKey)
        s.onRemove(wrappedEntry, Deleted)
        resetKeyFromEntry(wrappedEntry)
    }
    s.lock.Unlock()

    s.delhit()
    return nil
}
yasharthdubey commented 2 months ago

can i pick it?

janisz commented 2 months ago

Yes please, if you like to go one step further you can setup golangci-lint action to find even more issues.

yasharthdubey commented 2 months ago

thanks

yasharthdubey commented 1 month ago

this is fixed in newer version was looking in v 1.0.1