Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #155 from skogtwin/fixcvecache
Browse files Browse the repository at this point in the history
Fix #154.
  • Loading branch information
scottcunningham authored Jul 23, 2020
2 parents aed862a + b8e3bb4 commit 33c4eb7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cvefeed/cvecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func (c *Cache) Get(cpes []*wfn.Attributes) []MatchResult {
cves.res = c.match(cpes)
cves.updateResSize(key)
c.mu.Lock()
c.size += cves.size
if c.MaxSize != 0 && c.size > c.MaxSize {
c.evict(int64(cacheEvictPercentage * float64(c.MaxSize)))
if c.MaxSize != 0 && c.size+cves.size > c.MaxSize {
c.evict(int64(cacheEvictPercentage*float64(c.MaxSize)) + cves.size)
}
c.size += cves.size
cves.evictionIndex = c.evictionQ.push(key)
c.mu.Unlock()
close(cves.ready)
Expand Down Expand Up @@ -231,7 +231,7 @@ func (c *Cache) matchDict(cpes []*wfn.Attributes, dict Dictionary) (results []Ma
// evict the least recently used records untile nbytes of capacity is achieved or no more records left.
// It is not concurrency-safe, c.mu should be locked before calling it.
func (c *Cache) evict(nbytes int64) {
for c.size+nbytes > c.MaxSize {
for c.size > 0 && c.size+nbytes > c.MaxSize {
key := c.evictionQ.pop()
cd, ok := c.data[key]
if !ok { // should not happen
Expand Down

0 comments on commit 33c4eb7

Please sign in to comment.