Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a simple in-memory cache implementation. It utilizes a sync.RWMutex for concurrent read and write safety. The cache stores data as byte slices, using string keys for retrieval.
func NewCache ¶
func NewCache() *Cache
New creates and returns a new instance of the Cache with initialized internal data. The Cache is an in-memory cache implementation using a sync.RWMutex for concurrency safety. The internal data is represented as a map with string keys and byte slice values.
func (*Cache) Delete ¶
Delete removes the specified key from the cache. It acquires a write lock to ensure concurrent safety during deletion. The method returns nil, indicating a successful deletion.
func (*Cache) Get ¶
Get retrieves the value associated with the specified key from the cache. It acquires a read lock to ensure concurrent safety during retrieval. If the key is not found, an error is returned indicating the absence of the key. The retrieved value and a nil error are returned if the key is present in the cache.
func (*Cache) Has ¶
Has checks if the specified key exists in the cache. It acquires a read lock to ensure concurrent safety during the lookup. The method returns true if the key is found in the cache, and false otherwise.
func (*Cache) Set ¶
Set adds or updates the cache with the specified key-value pair. It acquires a write lock to ensure concurrent safety during insertion. If the time-to-live (TTL) duration is greater than zero, a goroutine is launched to remove the entry after the specified duration. The key-value pair is stored in the cache, and if a TTL is set, the entry is automatically deleted after the specified duration. The method returns nil, indicating a successful operation.
type Cacher ¶
type Cacher interface { // Get returns the value associated with the specified key. // If the key is not found or an error occurs, an error object is returned. Get(key []byte) ([]byte, error) // Set adds the value associated with the specified key to the cache with the specified expiration time. // If the duration is zero, the cache is held indefinitely. Set(key []byte, value []byte, expiration time.Duration) error // Has checks whether the specified key exists in the cache. Has(key []byte) bool // Delete removes the specified key from the cache. // If the key is not found, an error object is returned. Delete(key []byte) error }
https://github.com/mstgnz/ggcache Cacher is an interface used for performing caching operations. Applications can implement this interface to integrate different caching managers.