All Projects → gookit → cache

gookit / cache

Licence: MIT license
🗃 Generic cache use and cache manage. Provide a unified usage API by packaging various commonly used drivers. Support File, Memory, Redis, Memcached and more. Go 通用的缓存使用库,通过包装各种常用的驱动,来提供统一的使用API,便于使用。

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to cache

libcache
A caching library that provides an in-memory and file based cache for Ruby
Stars: ✭ 25 (-82.88%)
Mutual labels:  file-cache, memory-cache
hybrid-disk-cache
A hybrid disk cache library that utilized both the solid SQLite3 and file system.
Stars: ✭ 19 (-86.99%)
Mutual labels:  file-cache
salad
Asynchronous Scala Redis Client supporting Sentinel and Redis Cluster
Stars: ✭ 14 (-90.41%)
Mutual labels:  redis-cache
image-loader
Image loading library for Android
Stars: ✭ 19 (-86.99%)
Mutual labels:  memory-cache
sessionx
Go's web session library.
Stars: ✭ 75 (-48.63%)
Mutual labels:  redis-cache
Cache
📦 Nothing but Cache.
Stars: ✭ 2,491 (+1606.16%)
Mutual labels:  memory-cache
guava-cache-redis
implement guava cache interface backed by redis
Stars: ✭ 34 (-76.71%)
Mutual labels:  redis-cache
centminmod-magento2
Magento 2.2.2 Install Guide For Centmin Mod Nginx LEMP Stacks
Stars: ✭ 16 (-89.04%)
Mutual labels:  redis-cache
database-journal
Databases: Concepts, commands, codes, interview questions and more...
Stars: ✭ 50 (-65.75%)
Mutual labels:  redis-cache
.NetCorePluginManager
.Net Core Plugin Manager, extend web applications using plugin technology enabling true SOLID and DRY principles when developing applications
Stars: ✭ 17 (-88.36%)
Mutual labels:  memory-cache
memcacher
C++ implementation of Memcache Binary Protocol.
Stars: ✭ 16 (-89.04%)
Mutual labels:  memory-cache
SpeQL8
Speculative GraphQL metrics for your Postgres databases.
Stars: ✭ 73 (-50%)
Mutual labels:  redis-cache
CodablePersist
Store and Cache Anything Codable
Stars: ✭ 18 (-87.67%)
Mutual labels:  memory-cache
game 01
Scalable MMORPG game server based on entity control
Stars: ✭ 19 (-86.99%)
Mutual labels:  redis-cache
Uragano
Uragano, A simple, high performance RPC library. Support load balancing, circuit breaker, fallback, caching, intercepting.
Stars: ✭ 28 (-80.82%)
Mutual labels:  redis-cache
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 (-83.56%)
Mutual labels:  redis-cache
robin
robin provides a high performance golang goroutine library and job scheduling、in-memory cache for humans.
Stars: ✭ 28 (-80.82%)
Mutual labels:  memory-cache
cache
Laravel & Lumen Cache Service | File and Redis cache system
Stars: ✭ 19 (-86.99%)
Mutual labels:  redis-cache
tag-cache
Tagged Cache implementation over redis
Stars: ✭ 16 (-89.04%)
Mutual labels:  redis-cache
disk-lru-cache
💾 Disk LRU cache with persisted journal
Stars: ✭ 21 (-85.62%)
Mutual labels:  file-cache

Cache

GitHub go.mod Go version GoDoc Go Report Card Actions Status

中文说明

Generic cache use and cache manager for golang.

Provide a unified usage API by packaging various commonly used drivers.

All cache driver implemented the cache.Cache interface. So, You can add any custom driver.

Packaged Drivers:

Internal:

Notice: The built-in implementation is relatively simple and is not recommended for production environments; the production environment recommends using the third-party drivers listed above.

GoDoc

Install

The package supports 3 last Go versions and requires a Go version with modules support.

go get github.com/gookit/cache

Cache Interface

All cache driver implemented the cache.Cache interface. So, You can add any custom driver.

type Cache interface {
	// basic operation
	Has(key string) bool
	Get(key string) interface{}
	Set(key string, val interface{}, ttl time.Duration) (err error)
	Del(key string) error
	// multi operation
	GetMulti(keys []string) map[string]interface{}
	SetMulti(values map[string]interface{}, ttl time.Duration) (err error)
	DelMulti(keys []string) error
	// clear and close
	Clear() error
	Close() error
}

Usage

package main

import (
	"fmt"

	"github.com/gookit/cache"
	"github.com/gookit/cache/gcache"
	"github.com/gookit/cache/gocache"
	"github.com/gookit/cache/goredis"
	"github.com/gookit/cache/redis"
)

func main() {
	// register one(or some) cache driver
	cache.Register(cache.DvrFile, cache.NewFileCache(""))
	// cache.Register(cache.DvrMemory, cache.NewMemoryCache())
	cache.Register(gcache.Name, gcache.New(1000))
	cache.Register(gocache.Name, gocache.NewGoCache(cache.OneDay, cache.FiveMinutes))
	cache.Register(redis.Name, redis.Connect("127.0.0.1:6379", "", 0))
	cache.Register(goredis.Name, goredis.Connect("127.0.0.1:6379", "", 0))

	// setting default driver name
	cache.DefaultUse(gocache.Name)

	// quick use.(it is default driver)
	//
	// set
	cache.Set("name", "cache value", cache.TwoMinutes)
	// get
	val := cache.Get("name")
	// del
	cache.Del("name")

	// get: "cache value"
	fmt.Print(val)

	// More ...
	// fc := cache.Driver(gcache.Name)
	// fc.Set("key", "value", 10)
	// fc.Get("key")
}

With Options

gords := goredis.Connect("127.0.0.1:6379", "", 0)
gords.WithOptions(cache.WithPrefix("cache_"), cache.WithEncode(true))

cache.Register(goredis.Name, gords)

// set
// real key is: "cache_name"
cache.Set("name", "cache value", cache.TwoMinutes)

// get: "cache value"
val := cache.Get("name")

Gookit packages

  • gookit/ini Go config management, use INI files
  • gookit/rux Simple and fast request router for golang HTTP
  • gookit/gcli build CLI application, tool library, running CLI commands
  • gookit/slog Lightweight, extensible, configurable logging library written in Go
  • gookit/event Lightweight event manager and dispatcher implements by Go
  • gookit/cache Provide a unified usage API by packaging various commonly used drivers.
  • gookit/config Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags
  • gookit/color A command-line color library with true color support, universal API methods and Windows support
  • gookit/filter Provide filtering, sanitizing, and conversion of golang data
  • gookit/validate Use for data validation and filtering. support Map, Struct, Form data
  • gookit/goutil Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more
  • More, please see https://github.com/gookit

License

MIT

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].