Решение на ExpireMap от Евгений Бояджиев

Обратно към всички решения

Към профила на Евгений Бояджиев

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 1 успешни тест(а)
  • 24 неуспешни тест(а)

Код

package main
import (
"fmt"
"strconv"
"strings"
"sync"
"time"
)
func main() {
return
}
type CacheValue struct {
value interface{}
expire time.Time
delete chan struct{}
}
func NewCacheValue(value interface{}, expire time.Duration) *CacheValue {
return &CacheValue{
value: value,
expire: time.Now().Add(expire),
delete: make(chan struct{}),
}
}
type ExpireMap struct {
container map[string]*CacheValue
expired chan string
shutdown chan struct{}
wg *sync.WaitGroup
}
func NewExpireMap() *ExpireMap {
return &ExpireMap{
container: make(map[string]*CacheValue),
expired: make(chan string),
shutdown: make(chan struct{}),
wg: &sync.WaitGroup{},
}
}
func (em *ExpireMap) Set(key string, value interface{}, expire time.Duration) {
em.container[key] = NewCacheValue(value, expire)
em.wg.Add(1)
go cacheValueLifetime(em, key, expire)
}
func (em *ExpireMap) Get(key string) (interface{}, bool) {
val, ok := em.getCacheValue(key)
if !ok {
return nil, false
}
return val.value, true
}
func (em *ExpireMap) GetInt(key string) (int, bool) {
val, ok := em.Get(key)
if !ok {
return 0, false
}
result, ok := val.(int)
return result, ok
}
func (em *ExpireMap) GetFloat64(key string) (float64, bool) {
val, ok := em.Get(key)
if !ok {
return 0.0, false
}
result, ok := val.(float64)
return result, ok
}
func (em *ExpireMap) GetString(key string) (string, bool) {
val, ok := em.Get(key)
if !ok {
return "", false
}
result, ok := val.(string)
return result, ok
}
func (em *ExpireMap) GetBool(key string) (bool, bool) {
val, ok := em.Get(key)
if !ok {
return false, false
}
result, ok := val.(bool)
return result, ok
}
func (em *ExpireMap) Expires(key string) (time.Time, bool) {
val, ok := em.getCacheValue(key)
if !ok {
return time.Time{}, false
}
return val.expire, true
}
func (em *ExpireMap) Delete(key string) {
close(em.container[key].delete)
delete(em.container, key)
}
func (em *ExpireMap) Contains(key string) bool {
_, ok := em.Get(key)
return ok
}
func (em *ExpireMap) Size() int {
return len(em.container)
}
func (em *ExpireMap) Increment(key string) error {
err := em.add(key, 1)
if err != nil {
return newCacheError("Cannot increment the value")
}
return nil
}
func (em *ExpireMap) Decrement(key string) error {
err := em.add(key, -1)
if err != nil {
return newCacheError("Cannot decrement the value")
}
return nil
}
func (em *ExpireMap) ToUpper(key string) error {
str, ok := em.GetString(key)
if !ok {
return newCacheError("Cannot update value. Key does not exist or value is not of string type")
}
return em.updateValue(key, strings.ToUpper(str))
}
func (em *ExpireMap) ToLower(key string) error {
str, ok := em.GetString(key)
if !ok {
return newCacheError("Cannot update value. Key does not exist or value is not of string type")
}
return em.updateValue(key, strings.ToLower(str))
}
func (em *ExpireMap) ExpiredChan() <-chan string {
return em.expired
}
func (em *ExpireMap) Cleanup() {
for key, _ := range em.container {
em.Delete(key)
}
}
func (em *ExpireMap) Destroy() {
em.Cleanup()
close(em.shutdown)
}
/* Helper Methods */
func (em *ExpireMap) add(key string, integer int) error {
intVal, ok := em.GetInt(key)
if ok {
updatedValue := intVal + integer
em.updateValue(key, updatedValue)
return nil
}
stringVal, ok := em.GetString(key)
intVal, err := strconv.Atoi(stringVal)
if err == nil {
newValue := strconv.Itoa(intVal + integer)
em.updateValue(key, newValue)
return nil
}
return newCacheError("Cannot add the value. Incompatible type or non-existing key.")
}
func (em *ExpireMap) getCacheValue(key string) (*CacheValue, bool) {
value, ok := em.container[key]
return value, ok
}
func (em *ExpireMap) updateValue(key string, value interface{}) error {
_, ok := em.Get(key)
if !ok {
return newCacheError("Cannot update value. Key does not exist")
}
em.container[key].value = value
return nil
}
func cacheValueLifetime(em *ExpireMap, key string, expire time.Duration) {
defer em.wg.Done()
for {
select {
case <-time.After(expire):
em.Delete(key)
em.expired <- key
case <-em.container[key].delete:
case <-em.shutdown:
em.Delete(key)
}
}
}
/* Errors */
type ChacheError struct {
Message string
}
func (e *ChacheError) Error() string {
return fmt.Sprintf("ChacheError: %v", e.Message)
}
func newCacheError(message string) *ChacheError {
return &ChacheError{Message: message}
}

Лог от изпълнението

panic: runtime error: invalid memory address or nil pointer dereferencePASS

[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122e68, 0x3, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [panicwait]:
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.012s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351080, 0x8122f28, 0x3, 0xa13b8600, 0x1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351080, 0x8125178, 0x7, 0xa13b8600, 0x1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:197
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 7 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351080, 0x8124c88, 0x4, 0xa13b8600, 0x1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:197
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351080, 0x8125178, 0x7, 0xa13b8600, 0x1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.014s
panic: test timed out

goroutine 15 [running]:
testing.alarm()
	/usr/local/lib/go/src/pkg/testing/testing.go:533 +0x44
created by time.goFunc
	/usr/local/lib/go/src/pkg/time/sleep.go:122 +0x45

goroutine 1 [chan receive]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 4 [sleep]:
time.Sleep(0x3c336080, 0x0)
	/usr/local/lib/go/src/pkg/runtime/ztime_linux_386.c:19 +0x3a
_/tmp/d20141204-6466-13kx93a.TestSizes(0x183781e0)
	/tmp/d20141204-6466-13kx93a/solution_test.go:111 +0x3c9
testing.tRunner(0x183781e0, 0x81c2bb8)
	/usr/local/lib/go/src/pkg/testing/testing.go:353 +0x87
created by testing.RunTests
	/usr/local/lib/go/src/pkg/testing/testing.go:433 +0x684

goroutine 5 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300308, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 6 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300320, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 7 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300338, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 8 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300350, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 9 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300368, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 10 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300380, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 11 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300398, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 12 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183003b0, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 13 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183003c8, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 14 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183003e0, 0x5, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	1.013s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122e68, 0x3, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [chan receive]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 4 [sleep]:
time.Sleep(0x68e7780, 0x0)
	/usr/local/lib/go/src/pkg/runtime/ztime_linux_386.c:19 +0x3a
_/tmp/d20141204-6466-13kx93a.TestMultipleSetsOnTheSameKey(0x1837b120)
	/tmp/d20141204-6466-13kx93a/solution_test.go:148 +0x212
testing.tRunner(0x1837b120, 0x81c2bc4)
	/usr/local/lib/go/src/pkg/testing/testing.go:353 +0x87
created by testing.RunTests
	/usr/local/lib/go/src/pkg/testing/testing.go:433 +0x684

goroutine 6 [chan send]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122e68, 0x3, 0x5f5e100, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:203 +0x11f
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.112s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x807549f]

goroutine 6 [running]:
PASS
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122d48, 0x3, 0x11e1a300, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:206 +0x1cf
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [panicwait]:

goroutine 5 [chan send]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122e68, 0x3, 0x8f0d180, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:203 +0x11f
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.172s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122e68, 0x3, 0xb2d05e00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122d48, 0x3, 0xb2d05e00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:197
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122d48, 0x3, 0xb2d05e00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.012s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122e68, 0x3, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8124c18, 0x4, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:197
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8124c18, 0x4, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.012s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 9 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125158, 0x5, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 5 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122e68, 0x3, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125a68, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 7 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x812a1d8, 0x8, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 8 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81255d8, 0x7, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125a68, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.014s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122e68, 0x3, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125a68, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:197
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125a68, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.012s
panic: --- FAIL: TestIncAndDecInManyRoutines-2 (0.01 seconds)
	solution_test.go:388: Expected 666 but found 1409
runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x807549f]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125a68, 0x6, 0x502f9000, 0x9, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:206 +0x1cf
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).SetFAIL

	/tmp/d20141204-6466-13kx93a/solution.goexit status 1
FAIL	_/tmp/d20141204-6466-13kx93a	0.019s
panic: PASS
runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x812a2f8, 0xb, 0x2a05f200, 0x1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [panicwait]:
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.012s
panic: PASS
runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x812ae78, 0xb, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [panicwait]:
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.012s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125fe8, 0x4, 0x3ef79800, 0x15d, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 5 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122e68, 0x3, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 7 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8124f98, 0x4, 0xe8d60800, 0x29, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:197
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 7 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8124f98, 0x4, 0xe8d60800, 0x29, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.013s
panic: PASS
runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125048, 0x7, 0xb2c97000, 0x8b, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [panicwait]:
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.012s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125688, 0x4, 0x2faf080, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [chan receive]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 4 [select]:
_/tmp/d20141204-6466-13kx93a.TestExpiredChanExample(0x1837b1e0)
	/tmp/d20141204-6466-13kx93a/solution_test.go:498 +0x2a9
testing.tRunner(0x1837b1e0, 0x81c2c48)
	/usr/local/lib/go/src/pkg/testing/testing.go:353 +0x87
created by testing.RunTests
	/usr/local/lib/go/src/pkg/testing/testing.go:433 +0x684

goroutine 6 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125698, 0x4, 0x5f5e100, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.063s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122f48, 0x3, 0x2faf080, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8129fd8, 0x8, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8129fd8, 0x8, 0x3b9aca00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.063s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122f48, 0x3, 0x2625a00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8129fd8, 0x8, 0x7270e00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.072s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122f48, 0x3, 0x2faf080, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [chan receive]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 4 [select]:
_/tmp/d20141204-6466-13kx93a.TestExpiredChanDoesNotReturnDeletedKeys(0x1837c120)
	/tmp/d20141204-6466-13kx93a/solution_test.go:583 +0x4f7
testing.tRunner(0x1837c120, 0x81c2c6c)
	/usr/local/lib/go/src/pkg/testing/testing.go:353 +0x87
created by testing.RunTests
	/usr/local/lib/go/src/pkg/testing/testing.go:433 +0x684

goroutine 5 [select]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8129fd8, 0x8, 0x5f5e100, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.012s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8129fd8, 0x8, 0x5f5e100, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [chan receive]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 4 [select]:
_/tmp/d20141204-6466-13kx93a.TestExpiredChanDoesNotReturnCleanedupKeys(0x1837c180)
	/tmp/d20141204-6466-13kx93a/solution_test.go:610 +0x2f4
testing.tRunner(0x1837c180, 0x81c2c78)
	/usr/local/lib/go/src/pkg/testing/testing.go:353 +0x87
created by testing.RunTests
	/usr/local/lib/go/src/pkg/testing/testing.go:433 +0x684

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122f48, 0x3, 0x2faf080, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:197
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122f48, 0x3, 0x2faf080, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.012s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 141 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81255d8, 0x7, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 5 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81255d8, 0x7, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 6 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81260c8, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 123 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x184096d0, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 142 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81260c8, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 11 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300320, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 119 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x184096b8, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 15 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300338, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 61 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c5480, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 19 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300350, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 52 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81260c8, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 98 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81260c8, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 23 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300368, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 96 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81260c8, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 51 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81255d8, 0x7, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 27 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300380, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 127 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x184096e8, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 31 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18300398, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 35 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183003b0, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 57 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c5468, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 39 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183003c8, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 97 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81255d8, 0x7, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 43 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183003e0, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 131 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18409700, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 50 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81255d8, 0x7, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 49 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81260c8, 0x6, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 47 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183003f8, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 115 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x184096a0, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 65 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c5498, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 107 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18409670, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 69 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c54b0, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 73 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c54c8, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 103 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18409658, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 77 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c54e0, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 111 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18409688, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 81 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c54f8, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 85 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c5510, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 89 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c5528, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 95 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81255d8, 0x7, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 93 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x183c5540, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 135 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18409718, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 139 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18409730, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 103 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x18409658, 0x5, 0x8c2e2800, 0xd1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.069s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 10 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81256a8, 0x4, 0x42770c00, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 5 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351210, 0x8122f48, 0x3, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351210, 0x8125698, 0x4, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:206 +0x1cf
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 7 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351210, 0x81256a8, 0x4, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 8 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8122f48, 0x3, 0x42770c00, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 9 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125698, 0x4, 0x42770c00, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 11 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8126308, 0x6, 0xb2d05e00, 0x0, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:197
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x807549f]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351210, 0x8125698, 0x4, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:206 +0x1cf
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.014s
--- FAIL: TestDestroyMethodClosesExpireChannel-2 (0.05 seconds)
	solution_test.go:818: Expire channel was not closed in time
FAIL
exit status 1
FAIL	_/tmp/d20141204-6466-13kx93a	0.062s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125688, 0x4, 0x540be400, 0x2, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125698, 0x4, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:206 +0x1cf
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 7 [runnable]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x81256a8, 0x4, 0xa817c800, 0x4, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:200 +0x211
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x807549f]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x8125698, 0x4, 0x7e11d600, 0x3, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:206 +0x1cf
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.020s
PASS
ok  	_/tmp/d20141204-6466-13kx93a	0.272s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 6 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x812a3d8, 0xa, 0x2a05f200, 0x1, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9

goroutine 1 [runnable]:
testing.RunTests(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x1, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f
testing.Main(0x8148a74, 0x81c2ba0, 0x19, 0x19, 0x81c5600, ...)
	/usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69
main.main()
	_/tmp/d20141204-6466-13kx93a/_test/_testmain.go:91 +0x81

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x812adf8, 0xa, 0xd964b800, 0x45, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8075415]

goroutine 5 [running]:
_/tmp/d20141204-6466-13kx93a.cacheValueLifetime(0x18351200, 0x812adf8, 0xa, 0xd964b800, 0x45, ...)
	/tmp/d20141204-6466-13kx93a/solution.go:204 +0x145
created by _/tmp/d20141204-6466-13kx93a.(*ExpireMap).Set
	/tmp/d20141204-6466-13kx93a/solution.go:48 +0xb9
exit status 2
FAIL	_/tmp/d20141204-6466-13kx93a	0.013s

История (1 версия и 0 коментара)

Евгений обнови решението на 18.11.2014 09:10 (преди над 3 години)

+package main
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+ "sync"
+ "time"
+)
+
+func main() {
+ return
+}
+
+type CacheValue struct {
+ value interface{}
+ expire time.Time
+ delete chan struct{}
+}
+
+func NewCacheValue(value interface{}, expire time.Duration) *CacheValue {
+ return &CacheValue{
+ value: value,
+ expire: time.Now().Add(expire),
+ delete: make(chan struct{}),
+ }
+}
+
+type ExpireMap struct {
+ container map[string]*CacheValue
+ expired chan string
+ shutdown chan struct{}
+ wg *sync.WaitGroup
+}
+
+func NewExpireMap() *ExpireMap {
+ return &ExpireMap{
+ container: make(map[string]*CacheValue),
+ expired: make(chan string),
+ shutdown: make(chan struct{}),
+ wg: &sync.WaitGroup{},
+ }
+}
+
+func (em *ExpireMap) Set(key string, value interface{}, expire time.Duration) {
+ em.container[key] = NewCacheValue(value, expire)
+ em.wg.Add(1)
+ go cacheValueLifetime(em, key, expire)
+}
+
+func (em *ExpireMap) Get(key string) (interface{}, bool) {
+ val, ok := em.getCacheValue(key)
+ if !ok {
+ return nil, false
+ }
+ return val.value, true
+}
+
+func (em *ExpireMap) GetInt(key string) (int, bool) {
+ val, ok := em.Get(key)
+ if !ok {
+ return 0, false
+ }
+ result, ok := val.(int)
+ return result, ok
+}
+
+func (em *ExpireMap) GetFloat64(key string) (float64, bool) {
+ val, ok := em.Get(key)
+ if !ok {
+ return 0.0, false
+ }
+ result, ok := val.(float64)
+ return result, ok
+}
+
+func (em *ExpireMap) GetString(key string) (string, bool) {
+ val, ok := em.Get(key)
+ if !ok {
+ return "", false
+ }
+ result, ok := val.(string)
+ return result, ok
+}
+
+func (em *ExpireMap) GetBool(key string) (bool, bool) {
+ val, ok := em.Get(key)
+ if !ok {
+ return false, false
+ }
+ result, ok := val.(bool)
+ return result, ok
+}
+
+func (em *ExpireMap) Expires(key string) (time.Time, bool) {
+ val, ok := em.getCacheValue(key)
+ if !ok {
+ return time.Time{}, false
+ }
+ return val.expire, true
+}
+
+func (em *ExpireMap) Delete(key string) {
+ close(em.container[key].delete)
+ delete(em.container, key)
+}
+
+func (em *ExpireMap) Contains(key string) bool {
+ _, ok := em.Get(key)
+ return ok
+}
+
+func (em *ExpireMap) Size() int {
+ return len(em.container)
+}
+
+func (em *ExpireMap) Increment(key string) error {
+ err := em.add(key, 1)
+ if err != nil {
+ return newCacheError("Cannot increment the value")
+ }
+ return nil
+}
+
+func (em *ExpireMap) Decrement(key string) error {
+ err := em.add(key, -1)
+ if err != nil {
+ return newCacheError("Cannot decrement the value")
+ }
+ return nil
+}
+
+func (em *ExpireMap) ToUpper(key string) error {
+ str, ok := em.GetString(key)
+ if !ok {
+ return newCacheError("Cannot update value. Key does not exist or value is not of string type")
+ }
+ return em.updateValue(key, strings.ToUpper(str))
+}
+
+func (em *ExpireMap) ToLower(key string) error {
+ str, ok := em.GetString(key)
+ if !ok {
+ return newCacheError("Cannot update value. Key does not exist or value is not of string type")
+ }
+ return em.updateValue(key, strings.ToLower(str))
+}
+
+func (em *ExpireMap) ExpiredChan() <-chan string {
+ return em.expired
+}
+
+func (em *ExpireMap) Cleanup() {
+ for key, _ := range em.container {
+ em.Delete(key)
+ }
+}
+
+func (em *ExpireMap) Destroy() {
+ em.Cleanup()
+ close(em.shutdown)
+}
+
+/* Helper Methods */
+func (em *ExpireMap) add(key string, integer int) error {
+ intVal, ok := em.GetInt(key)
+ if ok {
+ updatedValue := intVal + integer
+ em.updateValue(key, updatedValue)
+ return nil
+ }
+ stringVal, ok := em.GetString(key)
+ intVal, err := strconv.Atoi(stringVal)
+ if err == nil {
+ newValue := strconv.Itoa(intVal + integer)
+ em.updateValue(key, newValue)
+ return nil
+ }
+
+ return newCacheError("Cannot add the value. Incompatible type or non-existing key.")
+}
+
+func (em *ExpireMap) getCacheValue(key string) (*CacheValue, bool) {
+ value, ok := em.container[key]
+ return value, ok
+}
+
+func (em *ExpireMap) updateValue(key string, value interface{}) error {
+ _, ok := em.Get(key)
+ if !ok {
+ return newCacheError("Cannot update value. Key does not exist")
+ }
+ em.container[key].value = value
+ return nil
+}
+
+func cacheValueLifetime(em *ExpireMap, key string, expire time.Duration) {
+ defer em.wg.Done()
+ for {
+ select {
+ case <-time.After(expire):
+ em.Delete(key)
+ em.expired <- key
+ case <-em.container[key].delete:
+ case <-em.shutdown:
+ em.Delete(key)
+ }
+ }
+}
+
+/* Errors */
+type ChacheError struct {
+ Message string
+}
+
+func (e *ChacheError) Error() string {
+ return fmt.Sprintf("ChacheError: %v", e.Message)
+}
+
+func newCacheError(message string) *ChacheError {
+ return &ChacheError{Message: message}
+}