nursik / go-expire-map Goto Github PK
View Code? Open in Web Editor NEWGo map with TTLs.
License: MIT License
Go map with TTLs.
License: MIT License
As it is mentioned in docs, expiration rate is limited to 2200 keys per second. So if there is a high unique keys insertion rate with small TTL (less than 1 hour), it is possible that map will consume a lot of memory, because it stores a lot of expired keys. So there are several improvements, which can solve this issue.
Some tests are failing on my setup:
=== RUN TestExpireMap_StoppedAndClose
--- PASS: TestExpireMap_StoppedAndClose (0.01s)
=== RUN TestExpireMap_Curtime
--- PASS: TestExpireMap_Curtime (5.00s)
expire_map_test.go:429: Curtime() - average diff 481423.750, max diff 1945113 (in nanosecs)
=== RUN TestExpireMap_Curtime_WithHeavyLoad
--- FAIL: TestExpireMap_Curtime_WithHeavyLoad (10.01s)
expire_map_test.go:489: Curtime() - average diff exceeded: max average diff 1000000.000, average diff 4419762.797 (in nanosecs)
=== RUN TestExpireMap_GetAll
--- PASS: TestExpireMap_GetAll (1.01s)
FAIL
exit status 1
I'm new to Golang but run into problem getting short-lived codes using go-expire-map.
We create the map:
exMap := expiremap.New()
defer exMap.Close()
and use it in two endpoints. In the first, we generate random code, put it into the map and pass the code to the user:
code := c.codes.Generate()
c.exMap.Set(code, true, time.Minute)
In the second, we check if the code is in the map. If it is, we delete it from the map and do our logic:
_, found := j.ExMap.Get(code)
if (!found) {
log.Printf("Not found code: %s", query)
w.WriteHeader(http.StatusBadRequest)
return
}
j.ExMap.Delete(code)
// our logic
Occasionally, I observe that when I check existence of the code returned to me earlier, the code is not found in the map. But the second check for the same code finds it.
Is this a bug or I use the library wrongly?
Since GO111MODULE=on
is gonna be default option starting from 1.13, consider adding modules support.
We may want to collect some metrics from a map, for example, rate of insertion, rate of expiration (active vs passive) etc.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.