-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track complete auth only for unique state
- Loading branch information
Showing
7 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/VictoriaMetrics/fastcache" | ||
) | ||
|
||
type countCache struct { | ||
*fastcache.Cache | ||
} | ||
|
||
func (cache *countCache) Set(key *string, count uint8) { | ||
cache.Cache.Set([]byte(*key), []byte{count}) | ||
} | ||
|
||
func (cache *countCache) Get(key *string) uint8 { | ||
countBytes, exists := cache.Cache.HasGet([]byte{}, []byte(*key)) | ||
if exists { | ||
return countBytes[0] | ||
} | ||
return 0 | ||
} | ||
|
||
func NewCountCache(maxBytes int) *countCache { | ||
return &countCache{ | ||
Cache: fastcache.New(maxBytes), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestCountCacheGetSet(t *testing.T) { | ||
cache := NewCountCache(1) | ||
|
||
t.Run("Valid time get-set", func(t *testing.T) { | ||
key := "key-1" | ||
expectedCount := uint8(6) | ||
|
||
cache.Set(&key, expectedCount) | ||
acualCount := cache.Get(&key) | ||
|
||
assert.Equal(t, expectedCount, acualCount, "Timestamp value is not expected") | ||
}) | ||
|
||
t.Run("Get not not exist value", func(t *testing.T) { | ||
key := "key-20" | ||
expectedValue := uint8(0) | ||
|
||
actualValue := cache.Get(&key) | ||
|
||
assert.Equal(t, expectedValue, actualValue, "Timestamp value is not expected") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters