Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example output is not matched with actual output #157

Open
rahfar opened this issue Sep 22, 2023 · 4 comments
Open

Example output is not matched with actual output #157

rahfar opened this issue Sep 22, 2023 · 4 comments

Comments

@rahfar
Copy link

rahfar commented Sep 22, 2023

Hi, I tried this example (go version go1.21.1 linux/amd64)
And instead of

value before expiration is found: true, value: "val1"
value after expiration is found: false, value: ""
Cache len: 1

got

value before expiration is found: true, value: "val1"
value after expiration is found: true, value: ""
Cache len: 2

Should I make pr to readme or lib is not supposed to work like this?

@rahfar
Copy link
Author

rahfar commented Sep 27, 2023

Discovered that the problem is in waiting for expiration, changing time from 12ms to 100ms fixed the behavior.
Can anybody explain such behavior - is it a bug specific to my machine or generally it is better to use bigger TTL values?

// wait for cache to expire
time.Sleep(time.Millisecond * 12)

@irenarindos
Copy link
Collaborator

I think you've run into this bug: #150 which has been fixed and will be in the next release

@rahfar
Copy link
Author

rahfar commented Sep 30, 2023

Tried with the latest version 2.0.7, but the behavior remains the same.
With a TTL of 10 ms (as in the example) and a sleep time of 90 ms, I am getting different results from time to time:

$ go run main.go 
value before expiration is found: true, value: "val1"
value after expiration is found: false, value: ""
Cache len: 2

$ go run main.go 
value before expiration is found: true, value: "val1"
value after expiration is found: false, value: ""
Cache len: 2

$ go run main.go 
value before expiration is found: true, value: "val1"
value after expiration is found: false, value: ""
Cache len: 1

$ go run main.go 
value before expiration is found: true, value: "val1"
value after expiration is found: false, value: ""
Cache len: 2

$ go run main.go 
value before expiration is found: true, value: "val1"
value after expiration is found: false, value: ""
Cache len: 2

$ go run main.go 
value before expiration is found: true, value: "val1"
value after expiration is found: false, value: ""
Cache len: 1

With sleep time of 190 ms works as expected.

In the new version value is found appears to be functioning correctly, but the length still appears to be asynchronous

@paskal
Copy link
Contributor

paskal commented Nov 30, 2023

I would propose to alter the example in the code and Readme to have values which produce consistent results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants