Skip to content

Commit

Permalink
rename resetKeyFromEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
yangtaoran committed May 5, 2023
1 parent 791a4b0 commit c485f08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ func readHashFromEntry(data []byte) uint64 {
return binary.LittleEndian.Uint64(data[timestampSizeInBytes:])
}

func resetKeyFromEntry(data []byte) {
func resetHashFromEntry(data []byte) {
binary.LittleEndian.PutUint64(data[timestampSizeInBytes:], 0)
}
8 changes: 4 additions & 4 deletions shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *cacheShard) set(key string, hashedKey uint64, entry []byte) error {

if previousIndex := s.hashmap[hashedKey]; previousIndex != 0 {
if previousEntry, err := s.entries.Get(int(previousIndex)); err == nil {
resetKeyFromEntry(previousEntry)
resetHashFromEntry(previousEntry)
//remove hashkey
delete(s.hashmap, hashedKey)
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func (s *cacheShard) addNewWithoutLock(key string, hashedKey uint64, entry []byt
func (s *cacheShard) setWrappedEntryWithoutLock(currentTimestamp uint64, w []byte, hashedKey uint64) error {
if previousIndex := s.hashmap[hashedKey]; previousIndex != 0 {
if previousEntry, err := s.entries.Get(int(previousIndex)); err == nil {
resetKeyFromEntry(previousEntry)
resetHashFromEntry(previousEntry)
}
}

Expand Down Expand Up @@ -265,7 +265,7 @@ func (s *cacheShard) del(hashedKey uint64) error {
if s.statsEnabled {
delete(s.hashmapStats, hashedKey)
}
resetKeyFromEntry(wrappedEntry)
resetHashFromEntry(wrappedEntry)
}
s.lock.Unlock()

Expand Down Expand Up @@ -332,7 +332,7 @@ func (s *cacheShard) removeOldestEntry(reason RemoveReason) error {
if err == nil {
hash := readHashFromEntry(oldest)
if hash == 0 {
// entry has been explicitly deleted with resetKeyFromEntry, ignore
// entry has been explicitly deleted with resetHashFromEntry, ignore
return nil
}
delete(s.hashmap, hash)
Expand Down

0 comments on commit c485f08

Please sign in to comment.