gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

store.go (1389B)


      1 package limiter
      2 
      3 import (
      4 	"context"
      5 	"time"
      6 )
      7 
      8 // Store is the common interface for limiter stores.
      9 type Store interface {
     10 	// Get returns the limit for given identifier.
     11 	Get(ctx context.Context, key string, rate Rate) (Context, error)
     12 	// Peek returns the limit for given identifier, without modification on current values.
     13 	Peek(ctx context.Context, key string, rate Rate) (Context, error)
     14 	// Reset resets the limit to zero for given identifier.
     15 	Reset(ctx context.Context, key string, rate Rate) (Context, error)
     16 	// Increment increments the limit by given count & gives back the new limit for given identifier
     17 	Increment(ctx context.Context, key string, count int64, rate Rate) (Context, error)
     18 }
     19 
     20 // StoreOptions are options for store.
     21 type StoreOptions struct {
     22 	// Prefix is the prefix to use for the key.
     23 	Prefix string
     24 
     25 	// MaxRetry is the maximum number of retry under race conditions on redis store.
     26 	// Deprecated: this option is no longer required since all operations are atomic now.
     27 	MaxRetry int
     28 
     29 	// CleanUpInterval is the interval for cleanup (run garbage collection) on stale entries on memory store.
     30 	// Setting this to a low value will optimize memory consumption, but will likely
     31 	// reduce performance and increase lock contention.
     32 	// Setting this to a high value will maximum throughput, but will increase the memory footprint.
     33 	CleanUpInterval time.Duration
     34 }