muesli / cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters
Other
2.12k stars 514 forks source link

Update cachetable.go #6

Closed xiaox0321 closed 7 years ago

xiaox0321 commented 8 years ago

code is repeated

muesli commented 8 years ago

It's not 100% the same actually. This will unlock the table before adding a new item, which could potentially lead to race conditions. The duplicated code still isn't nice obviously. I'd suggest moving the "add"-code into a separate function (that doesn't do the locking) and which gets called by both Add() and NotFoundAdd().

muesli commented 7 years ago

Fixed this in master.