https://github.com/teng231/smartcache
[deprecated] smart cache support memory insert, queryable and can add hook to remote cache save.
https://github.com/teng231/smartcache
cache caching inmemory inmemory-cache remote-caching
Last synced: about 1 year ago
JSON representation
[deprecated] smart cache support memory insert, queryable and can add hook to remote cache save.
- Host: GitHub
- URL: https://github.com/teng231/smartcache
- Owner: teng231
- License: mit
- Created: 2022-02-02T14:09:18.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-13T18:19:24.000Z (about 4 years ago)
- Last Synced: 2025-01-29T04:20:21.439Z (about 1 year ago)
- Topics: cache, caching, inmemory, inmemory-cache, remote-caching
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# SmartCache
> Upgrade from my dumbcache
[](https://pkg.go.dev/github.com/teng231/smartcache)
[](https://github.com/teng231/smartcache/actions/workflows/go.yml)
Hope it can be tool to help your works.
### Installation
```bash
go get github.com/teng231/smartcache
```
### How it work?
flow like that:
```bash
┌────────┐ ┌────────┐ ┌───────────────┐
│ │ │ │ │ │
│ Engine ├─────►│ Session├─────►│ Collection │
│ │ │ │ │ │
└────────┘ └────────┘ └───────────────┘
```
* When start app you create engine. Engine define structure of collection.
* Engine provider `select` to access module cache.
* Session process cache or set, get value to cache, from local module or remote module
* Collection local cache module
### Example
You can see full example here: [Example](https://github.com/teng231/smartcache/tree/master/example)
```go
cache := smartcache.Start(
&smartcache.CollectionConfig{
Key: "key1",
Capacity: 100,
},
)
if err := cache.Select(context.TODO(), "key1").Upsert("abc", 1); err != nil {
log.Print(err)
}
var out1 int
cache.Select(context.TODO(), "key1").Get("abc", nil).Exec(&out1)
log.Print(out1)
```
### Benmark Result:
follow link
[https://www.cloudbees.com/blog/real-life-go-benchmarking](https://www.cloudbees.com/blog/real-life-go-benchmarking)
```bash
$ go test -cpuprofile=cpu.out -benchmem -memprofile=mem.out -bench=BenchmarkEngineCacheWrite -run=^a
goos: linux
goarch: amd64
pkg: github.com/teng231/smartcache
cpu: Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
BenchmarkEngineCacheWrite/input_size_100-12 1000000000 0.0000460 ns/op 0 B/op 0 allocs/op
BenchmarkEngineCacheWrite/input_size_1000-12 1000000000 0.0004365 ns/op 0 B/op 0 allocs/op
BenchmarkEngineCacheWrite/input_size_74382-12 1000000000 0.05490 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/teng231/smartcache 0.513s
```
```bash
$ go test -cpuprofile=cpu.out -benchmem -memprofile=mem.out -bench=BenchmarkEngineCachex100000W10g -run=^a
goos: linux
goarch: amd64
pkg: github.com/teng231/smartcache
cpu: Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
BenchmarkEngineCachex100000W10g-12 1000000000 0.008111 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/teng231/smartcache 0.229s
```
Contributed:
[Quang Anh](github.com/)