Skip to content

Suppressor duplicated calls in distributed systems.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

moeryomenko/debouncer

Repository files navigation

Debouncer

Library for suppress duplicated calls in distributed systems.

Supported distributed cache and locker

  • Redis
  • Memcached
  • Tarantool(coming soon)

Usage

package main

import (
	"time"

	"github.com/moeryomenko/debouncer"
	cache "github.com/moeryomenko/ttlcache"
)

func main() {
	// create distributed suppressor.
	redisCache, redisLocker := adapters.NewRedisDriver(redis.NewClient(&redis.Options{Addr: "<ip:port>"}))

	suppressor, err := debouncer.NewDebouncer(debouncer.Config{
		Local: {
			TTL:      time.Second,
			Caceh:    cache.NewCache(100, cache.ARC),
		},
		Distributed: {
			Cache:  redisCache,
			Locker: redisLocker,
			Retry:  20 * time.Millisecond,
			TTL:    3 * time.Second,
		},
	})
	if err != nil {
		panic("could not create suppressor")
	}

	...

	result, err := suppressor.Do(key /* token for acquire fn */, fn)
	if err != nil {
		panic("something gone wrong")
	}

	...
}

License

Debouncer is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and/or LICENSE-MIT for details.

About

Suppressor duplicated calls in distributed systems.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published