Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

revert all future commits #1

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fe045e4
Fix leaking the janitor ticker when shutting down
databus23 Oct 13, 2015
a122e14
Merge pull request #23 from databus23/patch-1
patrickmn Oct 13, 2015
a0136a8
Don't expose the cache mutex
patrickmn Nov 27, 2015
3f2c810
Add OnEvicted()
patrickmn Nov 28, 2015
e9441b1
Add mutex-using test condition to TestOnEvicted
patrickmn Nov 28, 2015
ac0fcef
Clarify that the OnEvicted function isn't called when an item is over…
patrickmn Nov 28, 2015
0ba3e00
Update copyright years
patrickmn Nov 28, 2015
3d4d09c
Add a benchmark for DeleteExpired()
patrickmn Nov 28, 2015
901b241
Improve cache locality by removing Item-related pointers
patrickmn Nov 28, 2015
cf4e165
Add IncrementInt benchmark
patrickmn Nov 28, 2015
28ab885
Make BenchmarkDeleteExpired more meaningful
patrickmn Nov 28, 2015
a45ed98
Add benchmarks that use expiring items (time.Now calls) and rename Be…
patrickmn Nov 30, 2015
4e0d34e
Only get the current time once in the DeleteExpired loop
patrickmn Nov 30, 2015
31c7be0
'Inline' Get and Expired
patrickmn Nov 30, 2015
eb4f9f6
Use UnixNano int64s instead of Time
patrickmn Nov 30, 2015
8084bd0
Inline expiration checks manually for performance
patrickmn Nov 30, 2015
1924ec3
Remove expired() since it's no longer used (because of the inlining)
patrickmn Nov 30, 2015
01842a5
Use timevals
patrickmn Nov 30, 2015
2f60853
No need for emptyTime anymore
patrickmn Nov 30, 2015
2f0c74e
Use intermediary timevals
patrickmn Nov 30, 2015
f6cdd07
Merge branch 'timeval'
patrickmn Nov 30, 2015
afadf13
Back to UnixNano(), syscall dependency isn't worth a few nanoseconds …
patrickmn Nov 30, 2015
9fc6f9c
Add expiring/notexpiring sharded cache benchmarks
patrickmn Nov 30, 2015
7c1e7f5
go fmt
patrickmn Nov 30, 2015
76f1250
Make OnEvicted() a little faster
patrickmn Nov 30, 2015
d461c5d
'Inline' set in Set, and do time checks before the lock
patrickmn Dec 1, 2015
66bf7b7
Update README to point to new repository URL
patrickmn Dec 1, 2015
faf8383
Change GitHub repository URLs in README
patrickmn Dec 2, 2015
8c41258
Add BenchmarkRWMutexInterfaceMapGet
patrickmn Dec 3, 2015
721cc94
Add BenchmarkRWMutexInterfaceMapGetString
patrickmn Dec 3, 2015
5849ccb
remove mu.RUnlock call from get
patrickmn Jan 8, 2016
da6326c
added go syntax highlighting to README
darrenmcc Jan 27, 2016
1881a9b
Merge pull request #29 from darrenmcc/master
patrickmn Jan 27, 2016
a2d8b56
Make Items() return a copy rather than an unsynchronized reference to…
patrickmn Nov 25, 2016
9e6d911
Add 'inlining of expired' note to Items()
patrickmn Nov 25, 2016
5258177
LICENSE: Update copyright year
patrickmn Nov 25, 2016
e7a9def
Add SetDefault() for setting with the default expiration
patrickmn Nov 25, 2016
8c11fe2
Add GetWithExpiration
alexedwards Dec 8, 2016
dd1ed0b
README.md: Remove one level of indentation and increase 'recommended'…
patrickmn Mar 26, 2017
96426d0
README.md: Remove the unprotected change example since it would actua…
patrickmn Mar 26, 2017
ea4bd2a
LICENSE: Update copyright years
patrickmn Mar 26, 2017
7ac1518
Merge pull request #46 from alexedwards/master
patrickmn Apr 18, 2017
0640633
Fix race condition
inf-rno Jul 21, 2017
a3647f8
Merge pull request #64 from inf-rno/master
patrickmn Jul 22, 2017
9f6ff22
Fix benchmark for-loop shadowing
patrickmn May 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ code was contributed.)
Dustin Sallings <dustin@spy.net>
Jason Mooberry <jasonmoo@me.com>
Sergey Shepelev <temotor@gmail.com>
Alex Edwards <ajmedwards@gmail.com>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012-2014 Patrick Mylund Nielsen and the go-cache contributors
Copyright (c) 2012-2017 Patrick Mylund Nielsen and the go-cache contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
135 changes: 56 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,92 +15,69 @@ one) to recover from downtime quickly. (See the docs for `NewFrom()` for caveats

### Installation

`go get github.com/pmylund/go-cache`
`go get github.com/patrickmn/go-cache`

### Usage

import (
"fmt"
"github.com/pmylund/go-cache"
"time"
)

func main() {

// Create a cache with a default expiration time of 5 minutes, and which
// purges expired items every 30 seconds
c := cache.New(5*time.Minute, 30*time.Second)

// Set the value of the key "foo" to "bar", with the default expiration time
c.Set("foo", "bar", cache.DefaultExpiration)

// Set the value of the key "baz" to 42, with no expiration time
// (the item won't be removed until it is re-set, or removed using
// c.Delete("baz")
c.Set("baz", 42, cache.NoExpiration)

// Get the string associated with the key "foo" from the cache
foo, found := c.Get("foo")
if found {
fmt.Println(foo)
}

// Since Go is statically typed, and cache values can be anything, type
// assertion is needed when values are being passed to functions that don't
// take arbitrary types, (i.e. interface{}). The simplest way to do this for
// values which will only be used once--e.g. for passing to another
// function--is:
foo, found := c.Get("foo")
if found {
MyFunction(foo.(string))
}

// This gets tedious if the value is used several times in the same function.
// You might do either of the following instead:
if x, found := c.Get("foo"); found {
foo := x.(string)
// ...
}
// or
var foo string
if x, found := c.Get("foo"); found {
foo = x.(string)
}
// ...
// foo can then be passed around freely as a string

// Want performance? Store pointers!
c.Set("foo", &MyStruct, cache.DefaultExpiration)
if x, found := c.Get("foo"); found {
foo := x.(*MyStruct)
// ...
}

// If you store a reference type like a pointer, slice, map or channel, you
// do not need to run Set if you modify the underlying data. The cached
// reference points to the same memory, so if you modify a struct whose
// pointer you've stored in the cache, retrieving that pointer with Get will
// point you to the same data:
foo := &MyStruct{Num: 1}
c.Set("foo", foo, cache.DefaultExpiration)
// ...
x, _ := c.Get("foo")
foo := x.(*MyStruct)
fmt.Println(foo.Num)
// ...
foo.Num++
// ...
x, _ := c.Get("foo")
foo := x.(*MyStruct)
foo.Println(foo.Num)
```go
import (
"fmt"
"github.com/patrickmn/go-cache"
"time"
)

func main() {
// Create a cache with a default expiration time of 5 minutes, and which
// purges expired items every 10 minutes
c := cache.New(5*time.Minute, 10*time.Minute)

// Set the value of the key "foo" to "bar", with the default expiration time
c.Set("foo", "bar", cache.DefaultExpiration)

// Set the value of the key "baz" to 42, with no expiration time
// (the item won't be removed until it is re-set, or removed using
// c.Delete("baz")
c.Set("baz", 42, cache.NoExpiration)

// Get the string associated with the key "foo" from the cache
foo, found := c.Get("foo")
if found {
fmt.Println(foo)
}

// will print:
// 1
// 2
// Since Go is statically typed, and cache values can be anything, type
// assertion is needed when values are being passed to functions that don't
// take arbitrary types, (i.e. interface{}). The simplest way to do this for
// values which will only be used once--e.g. for passing to another
// function--is:
foo, found := c.Get("foo")
if found {
MyFunction(foo.(string))
}

// This gets tedious if the value is used several times in the same function.
// You might do either of the following instead:
if x, found := c.Get("foo"); found {
foo := x.(string)
// ...
}
// or
var foo string
if x, found := c.Get("foo"); found {
foo = x.(string)
}
// ...
// foo can then be passed around freely as a string

// Want performance? Store pointers!
c.Set("foo", &MyStruct, cache.DefaultExpiration)
if x, found := c.Get("foo"); found {
foo := x.(*MyStruct)
// ...
}
}
```

### Reference

`godoc` or [http://godoc.org/github.com/pmylund/go-cache](http://godoc.org/github.com/pmylund/go-cache)
`godoc` or [http://godoc.org/github.com/patrickmn/go-cache](http://godoc.org/github.com/patrickmn/go-cache)
Loading