All Projects → kofalt → go-memoize

kofalt / go-memoize

Licence: MIT license
An easy, no-frills memoizer for Go. Cache your expensive function calls.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-memoize

typescript-memoize
A memoize decorator for Typescript
Stars: ✭ 85 (+34.92%)
Mutual labels:  memoize
chimera
Lazy infinite compact streams with cache-friendly O(1) indexing and applications for memoization
Stars: ✭ 47 (-25.4%)
Mutual labels:  memoize
echo-mw
统一移到hb-go/echo-web ☞
Stars: ✭ 17 (-73.02%)
Mutual labels:  cache
Memoize One
A memoization library which only remembers the latest invocation
Stars: ✭ 2,649 (+4104.76%)
Mutual labels:  memoize
design-patterns-cpp14
🙏 Design patterns implemented in C++14
Stars: ✭ 35 (-44.44%)
Mutual labels:  memoize
souin
An HTTP cache system, RFC compliant, compatible with @TykTechnologies, @traefik, @caddyserver, @go-chi, @bnkamalesh, @beego, @devfeel, @labstack, @gofiber, @go-goyave, @gin-gonic, @zalando, @zeromicro, @nginx and @apache
Stars: ✭ 269 (+326.98%)
Mutual labels:  cache
Next Boost
Add a cache layer for server-side-rendered pages with stale-while-revalidate. Can be considered as an implementation of next.js's Incremental Static Regeneration which works with getServerSideProps.
Stars: ✭ 239 (+279.37%)
Mutual labels:  cache
nginx-cache
Node.js module to find files in an Nginx cache based on partial URL keys
Stars: ✭ 24 (-61.9%)
Mutual labels:  cache
p-cache
Decorator to memoize the results of async functions via lru-cache.
Stars: ✭ 21 (-66.67%)
Mutual labels:  memoize
storage-box
Intuitive and easy-to-use storage box.
Stars: ✭ 26 (-58.73%)
Mutual labels:  cache
regex-not
Create a javascript regular expression for matching everything except for the given string.
Stars: ✭ 31 (-50.79%)
Mutual labels:  memoize
memo-async-lru
Memoize Node.js style callback-last functions, using an in-memory LRU store
Stars: ✭ 17 (-73.02%)
Mutual labels:  memoize
hu
Small, generic functional helper library for node.js and browsers
Stars: ✭ 18 (-71.43%)
Mutual labels:  memoize
invokable
Objects are functions! Treat any Object or Class as a Proc (like Enumerable but for Procs).
Stars: ✭ 40 (-36.51%)
Mutual labels:  memoize
composer-velocita
Velocita - Composer plugin for transparent caching
Stars: ✭ 26 (-58.73%)
Mutual labels:  cache
Bus
Bus 是一个基础框架、服务套件,它基于Java8编写,参考、借鉴了大量已有框架、组件的设计,可以作为后端服务的开发基础中间件。代码简洁,架构清晰,非常适合学习使用。
Stars: ✭ 253 (+301.59%)
Mutual labels:  cache
kashe
A memoization library based on weakmaps. 🤯 Sometimes cache is kashe
Stars: ✭ 60 (-4.76%)
Mutual labels:  memoize
WP-Stash
Bridge between WordPress and StashPHP, providing a PSR6-compliant caching system for WordPress
Stars: ✭ 31 (-50.79%)
Mutual labels:  cache
node-cache-manager-ioredis
Redis store for node-cache-manager using IORedis.
Stars: ✭ 47 (-25.4%)
Mutual labels:  cache
onecache
One caching API, Multiple backends
Stars: ✭ 126 (+100%)
Mutual labels:  cache

go-memoize

There wasn't a decent memoizer for Golang out there, so I lashed two nice libraries together and made one.

Dead-simple. Safe for concurrent use.

PkgGoDev Report Card Build status

Project status

Complete. Latest commit timestamp might be old - that's okay.

Go-memoize has been in production for a few years, and has yet to burn the house down.

Usage

Cache expensive function calls in memory, with a configurable timeout and purge interval:

import (
	"time"

	"github.com/kofalt/go-memoize"
)

// Any expensive call that you wish to cache
expensive := func() (interface{}, error) {
	time.Sleep(3 * time.Second)
	return "some data", nil
}

// Cache expensive calls in memory for 90 seconds, purging old entries every 10 minutes.
cache := memoize.NewMemoizer(90*time.Second, 10*time.Minute)

// This will call the expensive func
result, err, cached := cache.Memoize("key1", expensive)

// This will be cached
result, err, cached = cache.Memoize("key1", expensive)

// This uses a new cache key, so expensive is called again
result, err, cached = cache.Memoize("key2", expensive)

In the example above, result is:

  1. the return value from your function if cached is false, or
  2. a previously stored value if cached is true.

All the hard stuff is punted to patrickmn's go-cache and the Go team's x/sync/singleflight, I just lashed them together.

Also note that cache.Storage is exported, so you can use the underlying cache features - such as Flush or SaveFile.

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