From 20415d82ed22829b27cdb1d381c1ca2491dfd006 Mon Sep 17 00:00:00 2001 From: Bruno Carlin Date: Sat, 20 Nov 2021 10:35:05 +0100 Subject: [PATCH] Add changelog, license and readme --- CHANGELOG.md | 5 +++++ LICENSE | 19 +++++++++++++++++++ README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8367004 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## v0.1.0 (unreleased) + +* First version diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1339f84 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..abdd8a0 --- /dev/null +++ b/README.md @@ -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/)