jftuga / ttlmap Goto Github PK
View Code? Open in Web Editor NEWA golang map in which entries expire after given a time period
License: MIT License
A golang map in which entries expire after given a time period
License: MIT License
I noticed a bug in ttlMap.Put()
: the value is only set in the item.Value
when the item is initially created, not on subsequent calls to Put
with the same key.
package main
import (
"fmt"
"time"
"github.com/jftuga/TtlMap"
)
func main() {
tm := TtlMap.New[string](time.Second*4, 3, time.Second, true)
defer tm.Close()
tm.Put("example", "original")
tm.Put("example", "revised")
fmt.Printf("Example value is %s\n", tm.Get("example"))
// Output:
// Example value is original
}
Setting the value just needs to be moved out of the if !ok
scope.
Love the concept of this. Would love to see a feature that allowed an override of the default TTL so any item could have it's own custom TTL.
Lines 118 to 120 in 1e9219b
The All()
method returns a direct reference to the internal map (m.m).
Any caller can then modify the map without acquiring the mutex, leading to potential race conditions.
Returning a deep map copy instead of a direct reference could be a solution.
Lines 49 to 70 in 1e9219b
The goroutine started in the New function will run indefinitely. This could lead to resource leaks.
Suggestion: Add a Close or Stop method to signal the goroutine to stop.
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.