Skip to content

A question about the eviction strategy #97

Closed
@anhoder

Description

I wrote a demo for otter, and its results puzzled me.

Otter uses the S3 FIFO eviction strategy, which works as shown in the following gif:
s3fifo_diagram

But in my demo, otter cleared the "0" that was hit the most.

playground

package main

import (
	"fmt"
	"time"

	"github.com/maypok86/otter"
)

func main() {
	t, err := otter.MustBuilder[int, int](64).Build()
	if err != nil {
		panic(err)
	}

	for i := range 128 {
		t.Set(i, i)

		t.Get(0)
	}

	fmt.Println(t.Get(0)) // 0 true

	time.Sleep(time.Second) // wait for eviction

	fmt.Println(t.Get(0)) // 0 false
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions