All Projects → bxcodec → gotcha

bxcodec / gotcha

Licence: MIT License
[Not Safe For Production] gotcha: inmemory-cache in Go (Golang) with customizable algorithm

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to gotcha

gocache
High performance and lightweight in-memory cache library with LRU and FIFO support as well as memory-usage-based-eviction
Stars: ✭ 15 (+15.38%)
Mutual labels:  inmemory, lru-cache, go-cache, inmemory-cache
Olric
Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
Stars: ✭ 2,067 (+15800%)
Mutual labels:  cache, lru-cache, inmemory-cache
cache
LRU-based cache package for Go.
Stars: ✭ 25 (+92.31%)
Mutual labels:  cache, lru-cache
elara
Elara DB is an easy to use, lightweight key-value database that can also be used as a fast in-memory cache. Manipulate data structures in-memory, encrypt database files and export data. 🎯
Stars: ✭ 93 (+615.38%)
Mutual labels:  cache, lru-cache
transitory
In-memory cache with high hit rates via LFU eviction for Node and browsers. Supports time-based expiration, automatic loading and metrics.
Stars: ✭ 24 (+84.62%)
Mutual labels:  cache, lfu-cache
disk-lru-cache
💾 Disk LRU cache with persisted journal
Stars: ✭ 21 (+61.54%)
Mutual labels:  cache, lru-cache
ultrafetch
Node-based fetch backed with an RFC-7234 compliant filesystem cache.
Stars: ✭ 30 (+130.77%)
Mutual labels:  cache, cache-control
GraphCMS-cache-boilerplate
The main goal of this service is to provide a reliable cache contingency backup plan in case a GraphCMS/GraphQL endpoint is failing.
Stars: ✭ 24 (+84.62%)
Mutual labels:  cache, cache-control
DTC
DTC is a high performance Distributed Table Cache system designed by JD.com that offering hotspot data cache for databases in order to reduce pressure of database and improve QPS.
Stars: ✭ 21 (+61.54%)
Mutual labels:  cache
AppleCache
Apple Content Cache Reverse Engineering
Stars: ✭ 82 (+530.77%)
Mutual labels:  cache
hitbox
A high-performance caching framework suitable for single-machine and for distributed applications in Rust
Stars: ✭ 61 (+369.23%)
Mutual labels:  cache
eloquent-cache
Easily cache your Laravel's Eloquent models.
Stars: ✭ 55 (+323.08%)
Mutual labels:  cache
bk flutter image
flutter image,降低内存使用
Stars: ✭ 32 (+146.15%)
Mutual labels:  cache
component-box
A little component cacher 📦
Stars: ✭ 25 (+92.31%)
Mutual labels:  cache
git-cache-http-server
A caching Git HTTP server
Stars: ✭ 65 (+400%)
Mutual labels:  cache
deflix-stremio
Deflix addon for Stremio
Stars: ✭ 31 (+138.46%)
Mutual labels:  cache
justreq
A caching proxy server for testing interface of HTTP or HTTPS. A never offline testing interface server. A mock server
Stars: ✭ 15 (+15.38%)
Mutual labels:  cache
magento2-LiteSpeed LiteMage
LiteMage Cache Extension for Magento 2
Stars: ✭ 27 (+107.69%)
Mutual labels:  cache
node-backend-template
A template for NodeJS backend projects
Stars: ✭ 19 (+46.15%)
Mutual labels:  cache
DaMaiProject
大麦界面,实现多种方式网络访问、数据缓存
Stars: ✭ 24 (+84.62%)
Mutual labels:  lrucache

gotcha

gotcha: inmemory-cache in Go (Golang) with customizable algorithm

GoDoc

Index

Support

You can file an Issue. See documentation in Godoc

Getting Started

Download

go get -u github.com/bxcodec/gotcha

Example

With Cache Client

package main

import (
	"fmt"
	"log"

	"github.com/bxcodec/gotcha"
)

func main() {
	cache := gotcha.New()
	err := cache.Set("name", "John Snow")
	if err != nil {
		log.Fatal(err)
	}
	val, err := cache.Get("name")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(val)
}

Without Cache Client

package main

import (
	"fmt"
	"log"

	"github.com/bxcodec/gotcha"
)

func main() {
	err := gotcha.Set("name", "John Snow")
	if err != nil {
		log.Fatal(err)
	}
	val, err := gotcha.Get("name")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(val)
}

With Custom Cache ALgorithm

You can also custom and change the algorithm, expiry-time and also maximum memory.

gotcha.NewOption().SetAlgorithm(cache.LRUAlgorithm).
	  SetExpiryTime(time.Minute * 10).
	  SetMaxSizeItem(100).
	  SetMaxMemory(cache.MB * 10)

Warn: Even gotcha support for MaxMemory, but the current version it's still using a simple json/encoding to count the byte size. So it will be slower if you set the MaxMemory.

Benchmark for LRU with/without MaxMemory

# With MaxMemory
20000000	      7878 ns/op	    1646 B/op	      20 allocs/op

# Without MaxMemory
200000000	       776 ns/op	     150 B/op	       6 allocs/op

If you seeking for fast performances and also your memory is high, ignore the MaxMemory options. I'm still looking for the better solutions for this problem. And if you have a better solutions, please kindly open and issue or submit a PR directly for the better results.

LRU

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/bxcodec/gotcha"
	"github.com/bxcodec/gotcha/cache"
)

func main() {
	cache := gotcha.New(
		gotcha.NewOption().SetAlgorithm(cache.LRUAlgorithm).
			SetExpiryTime(time.Minute * 10).SetMaxSizeItem(100),
	)
	err := cache.Set("Kue", "Nama")
	if err != nil {
		log.Fatal(err)
	}
	val, err := cache.Get("Kue")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(val)
}

LFU

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/bxcodec/gotcha"
	"github.com/bxcodec/gotcha/cache"
)

func main() {
	cache := gotcha.New(
		gotcha.NewOption().SetAlgorithm(cache.LFUAlgorithm).
			SetExpiryTime(time.Minute * 10).SetMaxSizeItem(100),
	)
	err := cache.Set("Kue", "Nama")
	if err != nil {
		log.Fatal(err)
	}
	val, err := cache.Get("Kue")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(val)
}

Contribution

  • You can submit an issue or create a Pull Request (PR)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].