github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/services/cache/cache.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package cache
     5  
     6  import (
     7  	"errors"
     8  	"time"
     9  )
    10  
    11  // ErrKeyNotFound is the error when the given key is not found
    12  var ErrKeyNotFound = errors.New("key not found")
    13  
    14  // Cache is a representation of a cache store that aims to replace cache.Cache
    15  type Cache interface {
    16  	// Purge is used to completely clear the cache.
    17  	Purge() error
    18  
    19  	// Set adds the given key and value to the store without an expiry. If the key already exists,
    20  	// it will overwrite the previous value.
    21  	Set(key string, value interface{}) error
    22  
    23  	// SetWithDefaultExpiry adds the given key and value to the store with the default expiry. If
    24  	// the key already exists, it will overwrite the previoous value
    25  	SetWithDefaultExpiry(key string, value interface{}) error
    26  
    27  	// SetWithExpiry adds the given key and value to the cache with the given expiry. If the key
    28  	// already exists, it will overwrite the previoous value
    29  	SetWithExpiry(key string, value interface{}, ttl time.Duration) error
    30  
    31  	// Get the content stored in the cache for the given key, and decode it into the value interface.
    32  	// Return ErrKeyNotFound if the key is missing from the cache
    33  	Get(key string, value interface{}) error
    34  
    35  	// Remove deletes the value for a given key.
    36  	Remove(key string) error
    37  
    38  	// Keys returns a slice of the keys in the cache.
    39  	Keys() ([]string, error)
    40  
    41  	// Len returns the number of items in the cache.
    42  	Len() (int, error)
    43  
    44  	// GetInvalidateClusterEvent returns the cluster event configured when this cache was created.
    45  	GetInvalidateClusterEvent() string
    46  
    47  	// Name returns the name of the cache
    48  	Name() string
    49  }