File: README.md

package info (click to toggle)
golang-github-mailgun-ttlmap 0.0~git20170619.c1c17f7-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 104 kB
  • sloc: makefile: 18
file content (26 lines) | stat: -rw-r--r-- 784 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
**This repo is deprecated, Renamed to TTLMap and moved to http://github.com/mailgun/holster**

[![Build Status](https://travis-ci.org/mailgun/ttlmap.png)](https://travis-ci.org/mailgun/ttlmap)

TtlMap
=======

Redis-like Map with expiry times and maximum capacity

```go

import "github.com/mailgun/ttlmap"

mh, _ := ttlmap.NewMap(20)
mh.Set("key1", "value", 20)
valI, exists := mh.Get("key2")
if exists {
   val := valI.(string)
}
```

The ttlmap is not thread safe by default. You can either create a thread safe
instance with `ttlmap.NewConcurrent` that is effectively using `sync.RWLock`,
or implement locking in you application. Beware though that at the application
level `sync.RWLock` cannot be used, because `ttlmap.Get` can occasionally
modifies the internal data structure.