All Projects → zekroTJA → timedmap

zekroTJA / timedmap

Licence: MIT license
A thread safe map which has expiring key-value pairs.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to timedmap

Time-and-Attendance-Management-System
TMS is a full-stack website that maintains records of all employees with their personal information. It keeps track of hours worked by an employee on a particular project assigned to him. It maintains time sheets and generates detailed and summary reports of the employee time sheets. TMS also has an admin page, which can manage all the employees…
Stars: ✭ 46 (-6.12%)
Mutual labels:  time
TimeContinuum
No description or website provided.
Stars: ✭ 28 (-42.86%)
Mutual labels:  time
jh-weapp-demo
微信小程序项目- 实现一些常用效果、封装通用组件和工具类
Stars: ✭ 60 (+22.45%)
Mutual labels:  map
nibbledb
a byte-sized time series database
Stars: ✭ 23 (-53.06%)
Mutual labels:  time
bvg-topological-map
BVG transport map as a nice SVG.
Stars: ✭ 15 (-69.39%)
Mutual labels:  map
time machine
A date and time API for Dart
Stars: ✭ 120 (+144.9%)
Mutual labels:  time
Timeline
AS2 & AS3 CPPS Emulator, written in Python. (Club Penguin Private Server Emulator)
Stars: ✭ 49 (+0%)
Mutual labels:  time
react-native-console-time-polyfill
console.time and console.timeEnd polyfill for react-native
Stars: ✭ 92 (+87.76%)
Mutual labels:  time
Co-ronaBD.info
Interactive Dashboard of Bangladesh for the Covid-19 Pandemic
Stars: ✭ 28 (-42.86%)
Mutual labels:  map
osm flutter
OpenStreetMap plugin for flutter
Stars: ✭ 121 (+146.94%)
Mutual labels:  map
clocklet
An opinionated clock-style vanilla-js timepicker.
Stars: ✭ 31 (-36.73%)
Mutual labels:  time
scala-js-momentjs
Scala.js façade for Moment.js
Stars: ✭ 45 (-8.16%)
Mutual labels:  time
scala-java-time
Implementation of the `java.time` API in scala. Especially useful for scala.js
Stars: ✭ 111 (+126.53%)
Mutual labels:  time
pssa
Singular Spectrum Analysis for time series forecasting in Python
Stars: ✭ 119 (+142.86%)
Mutual labels:  time
aws-map
Make a network graph of an AWS region
Stars: ✭ 79 (+61.22%)
Mutual labels:  map
time
The simplest but configurable online clock
Stars: ✭ 77 (+57.14%)
Mutual labels:  time
unist-util-map
utility to create a new tree by mapping all nodes
Stars: ✭ 30 (-38.78%)
Mutual labels:  map
TimesDates.jl
Nanosecond resolution for Time and Date, TimeZones
Stars: ✭ 28 (-42.86%)
Mutual labels:  time
AmapLike
【高仿】高德地图 包含定位、搜索、路径规划等功能 map bottomsheet
Stars: ✭ 51 (+4.08%)
Mutual labels:  map
kronos
Management of arithmetic operations on dates
Stars: ✭ 23 (-53.06%)
Mutual labels:  time

~ timedmap ~

A map which has expiring key-value pairs.

       

go get -u github.com/zekroTJA/timedmap

Intro

This package allows to set values to a map which will expire and disappear after a specified time.

Here you can read the docs of this package, generated by pkg.go.dev.


Usage Example

package main

import (
	"log"
	"time"

	"github.com/zekroTJA/timedmap"
)

func main() {
	// Create a timed map with a cleanup timer interval of 1 second
	tm := timedmap.New(1 * time.Second)
	// Set value of key "hey" to 213, which will expire after 3 seconds
	tm.Set("hey", 213, 3*time.Second)
	// Print the value of "hey"
	printKeyVal(tm, "hey")
	// Block the main thread for 5 seconds
	// After this time, the key-value pair "hey": 213 has expired
	time.Sleep(5 * time.Second)
	// Now, this function should show that there is no key "hey"
	// in the map, because it has been expired
	printKeyVal(tm, "hey")
}

func printKeyVal(tm *timedmap.TimedMap, key interface{}) {
	d, ok := tm.GetValue(key).(int)
	if !ok {
		log.Println("data expired")
		return
	}

	log.Printf("%v = %d\n", key, d)
}

Further examples, you can find in the example directory.

If you want to see this package in a practcal use case scenario, please take a look at the rate limiter implementation of the REST API of myrunes.com, where I have used timedmap for storing client-based limiter instances:
https://github.com/myrunes/backend/blob/master/internal/ratelimit/ratelimit.go


Copyright (c) 2020 zekro Development (Ringo Hoffmann).
Covered by MIT licence.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].