-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
5,613 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
cluster-autoscaler/cloudprovider/brightbox/go-cache/CONTRIBUTORS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
This is a list of people who have contributed code to go-cache. They, or their | ||
employers, are the copyright holders of the contributed code. Contributed code | ||
is subject to the license restrictions listed in LICENSE (as they were when the | ||
code was contributed.) | ||
|
||
Dustin Sallings <dustin@spy.net> | ||
Jason Mooberry <jasonmoo@me.com> | ||
Sergey Shepelev <temotor@gmail.com> | ||
Alex Edwards <ajmedwards@gmail.com> |
19 changes: 19 additions & 0 deletions
19
cluster-autoscaler/cloudprovider/brightbox/go-cache/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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 | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
83 changes: 83 additions & 0 deletions
83
cluster-autoscaler/cloudprovider/brightbox/go-cache/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# go-cache | ||
|
||
go-cache is an in-memory key:value store/cache similar to memcached that is | ||
suitable for applications running on a single machine. Its major advantage is | ||
that, being essentially a thread-safe `map[string]interface{}` with expiration | ||
times, it doesn't need to serialize or transmit its contents over the network. | ||
|
||
Any object can be stored, for a given duration or forever, and the cache can be | ||
safely used by multiple goroutines. | ||
|
||
Although go-cache isn't meant to be used as a persistent datastore, the entire | ||
cache can be saved to and loaded from a file (using `c.Items()` to retrieve the | ||
items map to serialize, and `NewFrom()` to create a cache from a deserialized | ||
one) to recover from downtime quickly. (See the docs for `NewFrom()` for caveats.) | ||
|
||
### Installation | ||
|
||
`go get github.com/patrickmn/go-cache` | ||
|
||
### Usage | ||
|
||
```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) | ||
} | ||
|
||
// 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/patrickmn/go-cache](http://godoc.org/github.com/patrickmn/go-cache) |
Oops, something went wrong.