8000 GitHub - jacobrandall/expiring-memory-store: Go implementation of an expiring key-value map
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jacobrandall/expiring-memory-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

expiring-memory-store Circle CI

Go implementation of an expiring key-value map

Installation

Install expiring-memory-store using the "go get" command:

go get github.com/skidder/expiring-memory-store/ems

The Go distribution and concurrent-map (a thread-safe map for Go) are the only dependencies.

Tests

Run the test suite from the ems directory:

$ git clone https://github.com/skidder/expiring-memory-store.git
$ cd expiring-memory-store/ems/
$ go test
PASS
ok  	_/Users/skidder/git/expiring-memory-store/ems	2.010s

Samples

Creating a new store

package main

import "github.com/skidder/expiring-memory-store/ems"

func main() {
	m := NewExpiringMemoryStore()
}

Writing to the store with the default expiration (20 seconds)

package main

import "github.com/skidder/expiring-memory-store/ems"

func main() {
	m := NewExpiringMemoryStore()
	m.Write("key", "value")
}

Writing to the store with a specific expiration

package main

import "github.com/skidder/expiring-memory-store/ems"

func main() {
	m := NewExpiringMemoryStore()

	// expire in 60 seconds
	m.WriteWithExpiration("key", "value", 60)
}

Read an item from the store

package main

import "time"
import "github.com/skidder/expiring-memory-store/ems"

func main() {
	m := NewExpiringMemoryStore()

	m.Write("key", "value")
	
	// val will have "value", and err will be nil
	val, err := m.Read("key")
	
 	// val will have "", and err equals ems.elementNotFoundError
	val, err := m.Read("missing")
  
	time.Sleep(time.Duration(30)*time.Second)

	// val will have "", and err equals ems.expiredElementError
	val, err := m.Read("key")
}

License

expiring-memory-store is available under the Apache License, Version 2.0.

About

Go implementation of an expiring key-value map

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0