Add changelog, license and readme
This commit is contained in:
parent
5611558820
commit
20415d82ed
3 changed files with 75 additions and 0 deletions
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Changelog
|
||||
|
||||
## v0.1.0 (unreleased)
|
||||
|
||||
* First version
|
19
LICENSE
Normal file
19
LICENSE
Normal file
|
@ -0,0 +1,19 @@
|
|||
MIT License Copyright (c) 2021 Bruno Carlin
|
||||
|
||||
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 c
|
||||
pies 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.
|
51
README.md
Normal file
51
README.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
# go/cache
|
||||
|
||||
Cache provides an in-memory key-value store used to cache arbitrary data.
|
||||
|
||||
It supports entry expiration.
|
||||
|
||||
## Quickstart
|
||||
|
||||
You can add `cache` to your project using `go get`:
|
||||
|
||||
go get code.bcarlin.xyz/go/cache
|
||||
|
||||
You can then import it in your code:
|
||||
|
||||
import "code.bcarlin.xyz/go/cache"
|
||||
|
||||
## Tests
|
||||
|
||||
To run the tests, run the command:
|
||||
|
||||
go test
|
||||
|
||||
## Usage
|
||||
|
||||
The API is very light and straight forward:
|
||||
|
||||
```go
|
||||
// Initialize a cache
|
||||
c := cache.New()
|
||||
|
||||
// Store some values. Keys must be strings.
|
||||
c.Put("foo", "my data")
|
||||
c.Put("the-answer", 42)
|
||||
|
||||
// Store some more data with an ewpiration date
|
||||
c.PutTTL("not-the-answer", 144, 1*time.Hour)
|
||||
|
||||
// Retrieve some data
|
||||
val, ok := c.Get("the-answer")
|
||||
if !ok {
|
||||
fmt.Println("cache missed")
|
||||
}
|
||||
|
||||
// Delete entries
|
||||
c.Del("foo")
|
||||
c.Del("does-not-exist") // does not fail
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://choosealicense.com/licenses/mit/)
|
Loading…
Reference in a new issue