Skip to content

Commit

Permalink
added comments to the exported default middleware methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Cosentino committed Jan 15, 2023
1 parent 09e7005 commit 11e3306
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
15 changes: 8 additions & 7 deletions middleware/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (mw LoggingMiddleware) GetMultiple(keys ...string) (result map[string]any,
return mw.next.GetMultiple(keys...)
}

// List
// List logs the time it takes to execute the next middleware.
func (mw LoggingMiddleware) List(filters ...any) ([]*models.Item, error) {
defer func(begin time.Time) {
mw.logger.Infof("method List took: %s", time.Since(begin))
Expand All @@ -77,7 +77,7 @@ func (mw LoggingMiddleware) List(filters ...any) ([]*models.Item, error) {
return mw.next.List(filters...)
}

// Remove
// Remove logs the time it takes to execute the next middleware.
func (mw LoggingMiddleware) Remove(keys ...string) {
defer func(begin time.Time) {
mw.logger.Infof("method Remove took: %s", time.Since(begin))
Expand All @@ -87,7 +87,7 @@ func (mw LoggingMiddleware) Remove(keys ...string) {
mw.next.Remove(keys...)
}

// Clear
// Clear logs the time it takes to execute the next middleware.
func (mw LoggingMiddleware) Clear() error {
defer func(begin time.Time) {
mw.logger.Infof("method Clear took: %s", time.Since(begin))
Expand All @@ -97,16 +97,17 @@ func (mw LoggingMiddleware) Clear() error {
return mw.next.Clear()
}

// Capacity
// Capacity logs the time it takes to execute the next middleware.
func (mw LoggingMiddleware) Capacity() int {
return mw.next.Capacity()
}

// Size
// Size logs the time it takes to execute the next middleware.
func (mw LoggingMiddleware) Size() int {
return mw.next.Size()
}

// TriggerEviction logs the time it takes to execute the next middleware.
func (mw LoggingMiddleware) TriggerEviction() {
defer func(begin time.Time) {
mw.logger.Infof("method TriggerEviction took: %s", time.Since(begin))
Expand All @@ -116,7 +117,7 @@ func (mw LoggingMiddleware) TriggerEviction() {
mw.next.TriggerEviction()
}

// Stop
// Stop logs the time it takes to execute the next middleware.
func (mw LoggingMiddleware) Stop() {
defer func(begin time.Time) {
mw.logger.Infof("method Stop took: %s", time.Since(begin))
Expand All @@ -126,7 +127,7 @@ func (mw LoggingMiddleware) Stop() {
mw.next.Stop()
}

// GetStats
// GetStats logs the time it takes to execute the next middleware.
func (mw LoggingMiddleware) GetStats() stats.Stats {
defer func(begin time.Time) {
mw.logger.Infof("method GetStats took: %s", time.Since(begin))
Expand Down
21 changes: 11 additions & 10 deletions middleware/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (mw StatsCollectorMiddleware) Get(key string) (interface{}, bool) {
return mw.next.Get(key)
}

// Set
// Set collects stats for the Set method.
func (mw StatsCollectorMiddleware) Set(key string, value any, expiration time.Duration) error {
start := time.Now()
defer func() {
Expand All @@ -40,7 +40,7 @@ func (mw StatsCollectorMiddleware) Set(key string, value any, expiration time.Du
return mw.next.Set(key, value, expiration)
}

// GetOrSet
// GetOrSet collects stats for the GetOrSet method.
func (mw StatsCollectorMiddleware) GetOrSet(key string, value any, expiration time.Duration) (any, error) {
start := time.Now()
defer func() {
Expand All @@ -50,7 +50,7 @@ func (mw StatsCollectorMiddleware) GetOrSet(key string, value any, expiration ti
return mw.next.GetOrSet(key, value, expiration)
}

// GetMultiple
// GetMultiple collects stats for the GetMultiple method.
func (mw StatsCollectorMiddleware) GetMultiple(keys ...string) (result map[string]any, failed map[string]error) {
start := time.Now()
defer func() {
Expand All @@ -60,7 +60,7 @@ func (mw StatsCollectorMiddleware) GetMultiple(keys ...string) (result map[strin
return mw.next.GetMultiple(keys...)
}

// List
// List collects stats for the List method.
func (mw StatsCollectorMiddleware) List(filters ...any) ([]*models.Item, error) {
start := time.Now()
defer func() {
Expand All @@ -70,6 +70,7 @@ func (mw StatsCollectorMiddleware) List(filters ...any) ([]*models.Item, error)
return mw.next.List(filters...)
}

// Remove collects stats for the Remove method.
func (mw StatsCollectorMiddleware) Remove(keys ...string) {
start := time.Now()
defer func() {
Expand All @@ -79,7 +80,7 @@ func (mw StatsCollectorMiddleware) Remove(keys ...string) {
mw.next.Remove(keys...)
}

// Clear
// Clear collects stats for the Clear method.
func (mw StatsCollectorMiddleware) Clear() error {
start := time.Now()
defer func() {
Expand All @@ -89,12 +90,12 @@ func (mw StatsCollectorMiddleware) Clear() error {
return mw.next.Clear()
}

// Capacity
// Capacity returns the capacity of the cache
func (mw StatsCollectorMiddleware) Capacity() int {
return mw.next.Capacity()
}

// TriggerEviction
// TriggerEviction triggers the eviction of the cache
func (mw StatsCollectorMiddleware) TriggerEviction() {
start := time.Now()
defer func() {
Expand All @@ -104,12 +105,12 @@ func (mw StatsCollectorMiddleware) TriggerEviction() {
mw.next.TriggerEviction()
}

// Size
// Size returns the size of the cache
func (mw StatsCollectorMiddleware) Size() int {
return mw.next.Size()
}

// Stop stops the cache
// Stop collects the stats for Stop methods and stops the cache and all its goroutines (if any)
func (mw StatsCollectorMiddleware) Stop() {
start := time.Now()
defer func() {
Expand All @@ -119,7 +120,7 @@ func (mw StatsCollectorMiddleware) Stop() {
mw.next.Stop()
}

// GetStats
// GetStats returns the stats of the cache
func (mw StatsCollectorMiddleware) GetStats() stats.Stats {
return mw.next.GetStats()
}

0 comments on commit 11e3306

Please sign in to comment.