Skip to content

Commit

Permalink
Remove redundant interface (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
erni27 committed Apr 14, 2023
1 parent c38002d commit 14d3d49
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 115 deletions.
52 changes: 0 additions & 52 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,55 +658,3 @@ func (s *Sharded[K, V]) StartCleaner(interval time.Duration) error {
func (s *Sharded[K, V]) StopCleaner() {
s.cleaner.stop()
}

// Imcache is the interface that wraps cache operations.
type Imcache[K comparable, V any] interface {
// Get returns the value for the given key.
Get(key K) (v V, present bool)
// Set sets the value for the given key.
// If the entry already exists, it is replaced.
//
// If you don't want to replace an existing entry, use the GetOrSet method instead.
// If you don't want to add a new entry if it doesn't exist, use the Replace method instead.
Set(key K, val V, exp Expiration)
// GetOrSet returns the value for the given key and true if it exists,
// otherwise it sets the value for the given key and returns the set value and false.
GetOrSet(key K, val V, exp Expiration) (v V, present bool)
// Replace replaces the value for the given key.
// It returns true if the value is present and replaced, otherwise it returns false.
//
// If you want to add or replace an entry, use the Set method instead.
Replace(key K, val V, exp Expiration) (present bool)
// ReplaceWithFunc replaces the value for the given key
// with the result of the given function that takes the old value as an argument.
// It returns true if the value is present and replaced, otherwise it returns false.
//
// If you want to replace the value with a new value not depending on the old value,
// use the Replace method instead.
ReplaceWithFunc(key K, f func(old V) (new V), exp Expiration) (present bool)
// Remove removes the cache entry for the given key.
//
// It returns true if the entry is present and removed,
// otherwise it returns false.
Remove(key K) (present bool)
// RemoveAll removes all entries.
RemoveAll()
// RemoveStale removes all expired entries.
RemoveStale()
// GetAll returns a copy of all entries in the cache.
GetAll() map[K]V
// Len returns the number of entries in the cache.
Len() int
// StartCleaner starts a cleaner that periodically removes expired entries.
// A cleaner runs in a separate goroutine.
// It's a NOP method if the cleaner is already running.
// It returns an error if the cleaner is already running
// or if the interval is less than or equal to zero.
//
// The cleaner can be stopped by calling StopCleaner method.
StartCleaner(interval time.Duration) error
// StopCleaner stops the cleaner.
// It is a blocking method that waits for the cleaner to stop.
// It's a NOP method if the cleaner is not running.
StopCleaner()
}

0 comments on commit 14d3d49

Please sign in to comment.