Skip to content

Eviction not working as expected #3

@ghz-max

Description

@ghz-max

First of all, awesome work! Very promising.

That being said, I may I found a bug in the following situation:

Step to reproduce

        var cacheSize int64 = 1000
	client, err := theine.NewBuilder[string, string](cacheSize).RemovalListener(func(key string, value string, reason theine.RemoveReason) {
		fmt.Println("removal", key, value, reason)
	}).Build()
	if err != nil {
		panic(err)
	}
	client.Set("test_key", "test_value", 500)
	fmt.Println(client.Get("test_key"))
	client.Set("test_2_key", "test_2_value", 500)
	fmt.Println(client.Get("test_2_key"))
	client.Set("test_3_key", "test_3_value", 600)
	fmt.Println(client.Get("test_3_key"))
	// wait for the eviction to proceed
	time.Sleep(time.Second)
	fmt.Println(client.Get("test_3_key"))

Expected

test_value true
test_2_value true
test_3_value true
removal test_key test_value 1
removal test_2_key test_2_value 1
test_3_value true

Actually returned

test_value true
test_2_value true
test_3_value true
removal test_3_key test_3_value 1
 false

This particular behavior seems to happens only when the sum of key's cost equals cacheSize

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions