### Get the Beginning Position of the Ring Buffer Source: https://pkg.go.dev/github.com/coocood/freecache Begin returns the current starting position of the data within the RingBuf. ```go func (rb *RingBuf) Begin() int64 ``` -------------------------------- ### Create a New Ring Buffer Source: https://pkg.go.dev/github.com/coocood/freecache NewRingBuf initializes and returns a new RingBuf with a specified size and starting position. ```go func NewRingBuf(size int, begin int64) (rb RingBuf) ``` -------------------------------- ### Get Cache Values Source: https://pkg.go.dev/github.com/coocood/freecache Methods to retrieve values from the cache, including variants for specific key types and zero-copy access. ```go func (cache *Cache) Get(key []byte) (value []byte, err error) ``` ```go func (cache *Cache) GetFn(key []byte, fn func([]byte) error) (err error) ``` ```go func (cache *Cache) GetInt(key int64) (value []byte, err error) ``` ```go func (cache *Cache) GetIntWithExpiration(key int64) (value []byte, expireAt uint32, err error) ``` ```go func (cache *Cache) GetOrSet(key, value []byte, expireSeconds int) (retValue []byte, err error) ``` ```go func (cache *Cache) GetWithBuf(key, buf []byte) (value []byte, err error) ``` ```go func (cache *Cache) GetWithExpiration(key []byte) (value []byte, expireAt uint32, err error) ``` ```go func (cache *Cache) GetWithExpirationAndBuf(key []byte, buf []byte) (value []byte, expireAt uint32, err error) ``` -------------------------------- ### Cache Operations Source: https://pkg.go.dev/github.com/coocood/freecache Methods for interacting with the Cache instance, including getting, setting, and deleting data. ```APIDOC ## Cache Operations ### Description Methods for interacting with the Cache instance, including getting, setting, deleting, and retrieving various statistics. ### Methods #### Get ```go func (cache *Cache) Get(key []byte) (value []byte, err error) ``` **Description:** Retrieves the value associated with the given key. #### Set ```go func (cache *Cache) Set(key, value []byte, expireSeconds int) (err error) ``` **Description:** Sets a key-value pair in the cache with a specified expiration time in seconds. #### Del ```go func (cache *Cache) Del(key []byte) (affected bool) ``` **Description:** Deletes the entry associated with the given key. Returns true if an entry was deleted, false otherwise. #### GetOrSet ```go func (cache *Cache) GetOrSet(key, value []byte, expireSeconds int) (retValue []byte, err error) ``` **Description:** Retrieves the value for a key, or sets it if it doesn't exist. Returns the existing or newly set value. #### GetWithExpiration ```go func (cache *Cache) GetWithExpiration(key []byte) (value []byte, expireAt uint32, err error) ``` **Description:** Retrieves the value and its expiration timestamp for the given key. #### GetWithExpirationAndBuf ```go func (cache *Cache) GetWithExpirationAndBuf(key []byte, buf []byte) (value []byte, expireAt uint32, err error) ``` **Description:** Retrieves the value and its expiration timestamp using a provided buffer for efficiency. #### GetInt ```go func (cache *Cache) GetInt(key int64) (value []byte, err error) ``` **Description:** Retrieves the value associated with an integer key. #### SetInt ```go func (cache *Cache) SetInt(key int64, value []byte, expireSeconds int) (err error) ``` **Description:** Sets a key-value pair in the cache using an integer key with a specified expiration time. #### DelInt ```go func (cache *Cache) DelInt(key int64) (affected bool) ``` **Description:** Deletes the entry associated with the given integer key. #### GetIntWithExpiration ```go func (cache *Cache) GetIntWithExpiration(key int64) (value []byte, expireAt uint32, err error) ``` **Description:** Retrieves the value and its expiration timestamp for an integer key. #### MultiGet ```go func (cache *Cache) MultiGet(keys [][]byte) (values [][]byte, errs []error) ``` **Description:** Retrieves multiple values from the cache for a given list of keys. #### Peek ```go func (cache *Cache) Peek(key []byte) (value []byte, err error) ``` **Description:** Retrieves the value associated with the key without updating its access time. #### PeekWithExpiration ```go func (cache *Cache) PeekWithExpiration(key []byte) (value []byte, expireAt uint32, err error) ``` **Description:** Retrieves the value and its expiration timestamp without updating the access time. #### TTL ```go func (cache *Cache) TTL(key []byte) (timeLeft uint32, err error) ``` **Description:** Returns the remaining time-to-live for a given key in seconds. #### Touch ```go func (cache *Cache) Touch(key []byte, expireSeconds int) (err error) ``` **Description:** Updates the expiration time for an existing key. #### SetAndGet ```go func (cache *Cache) SetAndGet(key, value []byte, expireSeconds int) (retValue []byte, found bool, err error) ``` **Description:** Sets a key-value pair and returns the previous value if it existed. #### Update ```go func (cache *Cache) Update(key []byte, updater Updater) (found bool, replaced bool, err error) ``` **Description:** Updates an existing entry using an updater function. Returns whether the entry was found and replaced. ``` -------------------------------- ### Get Average Access Time Source: https://pkg.go.dev/github.com/coocood/freecache Retrieves the average Unix timestamp when entries were last accessed. This metric is used to prioritize eviction of older entries. ```go func (cache *Cache) AverageAccessTime() int64 ``` -------------------------------- ### Get Time To Live for a Cache Key Source: https://pkg.go.dev/github.com/coocood/freecache TTL returns the remaining time-to-live for a given cache key. It returns a not found error if the key does not exist. ```go func (cache *Cache) TTL(key []byte) (timeLeft uint32, err error) ``` -------------------------------- ### Get Count of Touched Cache Entries Source: https://pkg.go.dev/github.com/coocood/freecache TouchedCount returns the total number of times cache entries have had their expiration times extended. ```go func (cache *Cache) TouchedCount() (touchedCount int64) ``` -------------------------------- ### Initialize and Use FreeCache Source: https://pkg.go.dev/github.com/coocood/freecache Demonstrates basic cache initialization, setting values with expiration, retrieving values, and deleting entries. ```go // In bytes, where 1024 * 1024 represents a single Megabyte, and 100 * 1024*1024 represents 100 Megabytes. cacheSize := 100 * 1024 * 1024 cache := freecache.NewCache(cacheSize) debug.SetGCPercent(20) key := []byte("abc") val := []byte("def") expire := 60 // expire in 60 seconds cache.Set(key, val, expire) got, err := cache.Get(key) if err != nil { fmt.Println(err) } else { fmt.Printf("%s\n", got) } affected := cache.Del(key) fmt.Println("deleted key ", affected) fmt.Println("entry count ", cache.EntryCount()) ``` -------------------------------- ### Initialize New Cache Source: https://pkg.go.dev/github.com/coocood/freecache Creates and initializes a new cache instance with a specified size. The minimum cache size is 512KB. For large cache sizes, consider adjusting GC settings using `debug.SetGCPercent()` to manage memory and GC pause times. ```go func NewCache(size int) (cache *Cache) ``` -------------------------------- ### Initialize Cache with Custom Timer Source: https://pkg.go.dev/github.com/coocood/freecache Creates a new cache instance using a provided custom timer. This allows for more control over cache expiration and eviction timing. ```go func NewCacheCustomTimer(size int, timer Timer) (cache *Cache) ``` -------------------------------- ### Benchmark Results Source: https://pkg.go.dev/github.com/coocood/freecache Performance comparison between FreeCache and the built-in Go map. ```text BenchmarkCacheSet 3000000 446 ns/op BenchmarkMapSet 2000000 861 ns/op BenchmarkCacheGet 3000000 517 ns/op BenchmarkMapGet 10000000 212 ns/op ``` -------------------------------- ### Cache Initialization Source: https://pkg.go.dev/github.com/coocood/freecache Functions for creating and initializing a new Cache instance. ```APIDOC ## Cache Initialization ### Description Functions to create and initialize a new Cache instance with specified size. ### Functions #### NewCache ```go func NewCache(size int) (cache *Cache) ``` **Description:** Returns a newly initialized cache by size. The cache size will be set to 512KB at minimum. If the size is set relatively large, you should call `debug.SetGCPercent()`, set it to a much smaller value to limit the memory consumption and GC pause time. #### NewCacheCustomTimer ```go func NewCacheCustomTimer(size int, timer Timer) (cache *Cache) ``` **Description:** Returns a new cache with a custom timer. (Added in v1.1.1) ``` -------------------------------- ### Zero-Copy Peek with Function Callback Source: https://pkg.go.dev/github.com/coocood/freecache PeekFn provides a zero-copy way to access cache entry values by passing a slice view to a provided function. It avoids buffer allocation unless the value wraps around the ring buffer. Returns ErrNotFound if the key is not present, and errors from the callback function are propagated. Warning: No expiry check is performed. ```go func (cache *Cache) PeekFn(key []byte, fn func([]byte) error) (err error) ``` -------------------------------- ### Retrieve Cache Metrics Source: https://pkg.go.dev/github.com/coocood/freecache Methods to retrieve various performance and state metrics from the cache. ```go func (cache *Cache) EntryCount() (entryCount int64) ``` ```go func (cache *Cache) EvacuateCount() (count int64) ``` ```go func (cache *Cache) ExpiredCount() (count int64) ``` ```go func (cache *Cache) HitCount() (count int64) ``` ```go func (cache *Cache) HitRate() float64 ``` ```go func (cache *Cache) LookupCount() int64 ``` ```go func (cache *Cache) MissCount() (count int64) ``` ```go func (cache *Cache) OverwriteCount() (overwriteCount int64) ``` -------------------------------- ### Create Cache Iterator Source: https://pkg.go.dev/github.com/coocood/freecache Initializes a new iterator for traversing the cache. ```go func (cache *Cache) NewIterator() *Iterator ``` -------------------------------- ### Clear Cache Source: https://pkg.go.dev/github.com/coocood/freecache Removes all items from the cache. ```go func (cache *Cache) Clear() ``` -------------------------------- ### RingBuf Methods Source: https://pkg.go.dev/github.com/coocood/freecache Methods for interacting with the RingBuf data structure. ```APIDOC ## RingBuf Methods ### Dump - **Description**: Create a copy of the buffer. - **Signature**: `func (*RingBuf) Dump() []byte` ### Evacuate - **Description**: Read the data at off, then write it to the data stream to keep it from being overwritten. - **Signature**: `func (*RingBuf) Evacuate(off int64, length int) (newOff int64)` ### ReadAt - **Description**: Read up to len(p) at off of the data stream. - **Signature**: `func (*RingBuf) ReadAt(p []byte, off int64) (n int, err error)` ### Reset - **Description**: Reset the ring buffer. - **Parameters**: `begin` (int64) - Required - Beginning offset of the data stream. - **Signature**: `func (*RingBuf) Reset(begin int64)` ### Slice - **Description**: Returns a slice of the supplied range of the ring buffer. It will not alloc unless the requested range wraps the ring buffer. - **Signature**: `func (*RingBuf) Slice(off, length int64) ([]byte, error)` ``` -------------------------------- ### Define Entry Header Size Constant Source: https://pkg.go.dev/github.com/coocood/freecache Defines the size of the entry header in bytes. This is a fundamental constant for internal cache structure. ```go const ENTRY_HDR_SIZE = 24 ``` -------------------------------- ### Error for Large Entry Source: https://pkg.go.dev/github.com/coocood/freecache Represents an error when an entry size exceeds the allowed cache size ratio (1/1024). ```go var ErrLargeEntry = errors.New("The entry size is larger than 1/1024 of cache size") ``` -------------------------------- ### Timer Interfaces Source: https://pkg.go.dev/github.com/coocood/freecache Interfaces and constructors for cache timers. ```APIDOC ## Timer Interfaces ### NewCachedTimer - **Description**: Create cached timer and start runtime timer that updates time every second. - **Signature**: `func NewCachedTimer() StoppableTimer` ### StoppableTimer - **Description**: Timer that must be stopped. User must call Stop() once to release resources. - **Signature**: `type StoppableTimer interface { Stop() }` ### Timer - **Description**: Timer holds representation of current time. - **Signature**: `type Timer interface { Now() uint32 }` ``` -------------------------------- ### Set Cache Entry and Retrieve Existing Value Source: https://pkg.go.dev/github.com/coocood/freecache SetAndGet stores a key-value pair with expiration and returns the existing value if the key was already present. It adheres to the same size constraints as Set. An expireSeconds value of 0 or less means no expiration, but eviction may occur if the cache is full. ```go func (cache *Cache) SetAndGet(key, value []byte, expireSeconds int) (retValue []byte, found bool, err error) ``` -------------------------------- ### Set Cache Entry with Expiration Source: https://pkg.go.dev/github.com/coocood/freecache Set stores a key-value pair with a specified expiration time. Entries exceeding key size limits (65535 bytes) or value size limits (1/1024 of cache size) will not be stored. An expireSeconds value of 0 or less means no expiration, but the entry may be evicted if the cache is full. ```go func (cache *Cache) Set(key, value []byte, expireSeconds int) (err error) ``` -------------------------------- ### Cache Metrics Source: https://pkg.go.dev/github.com/coocood/freecache Methods for retrieving performance and usage metrics from the cache. ```APIDOC ## EntryCount ### Description Returns the number of items currently in the cache. ## HitCount ### Description Returns the number of times a key was found in the cache. ## HitRate ### Description Returns the ratio of hits over lookups. ## MissCount ### Description Returns the number of times a miss occurred in the cache. ## EvacuateCount ### Description Metric indicating the number of times an eviction occurred. ## ExpiredCount ### Description Metric indicating the number of times an expire occurred. ``` -------------------------------- ### Constants and Variables Source: https://pkg.go.dev/github.com/coocood/freecache Definitions of constants and variables used within the Freecache package. ```APIDOC ## Constants and Variables ### Constants #### ENTRY_HDR_SIZE ```go const ENTRY_HDR_SIZE = 24 ``` **Description:** Size of the entry header in bytes. #### HASH_ENTRY_SIZE ```go const HASH_ENTRY_SIZE = 16 ``` **Description:** Size of a hash entry in bytes. ### Variables #### ErrLargeEntry ```go var ErrLargeEntry = errors.New("The entry size is larger than 1/1024 of cache size") ``` **Description:** Error returned when an entry is too large for the cache. #### ErrLargeKey ```go var ErrLargeKey = errors.New("The key is larger than 65535") ``` **Description:** Error returned when a key is too large. #### ErrNotFound ```go var ErrNotFound = errors.New("Entry not found") ``` **Description:** Error returned when an entry is not found in the cache. #### ErrOutOfRange ```go var ErrOutOfRange = errors.New("out of range") ``` **Description:** Error returned when an operation is out of the valid range. ``` -------------------------------- ### Error for Large Key Source: https://pkg.go.dev/github.com/coocood/freecache Represents an error when a key size exceeds the maximum allowed limit of 65535 bytes. ```go var ErrLargeKey = errors.New("The key is larger than 65535") ``` -------------------------------- ### Advance Iterator to Next Cache Entry Source: https://pkg.go.dev/github.com/coocood/freecache Next returns the subsequent entry from the iterator. If no more entries are available, it returns nil. The iteration order is not guaranteed. ```go func (it *Iterator) Next() *Entry ``` -------------------------------- ### Cache Entry Structure Source: https://pkg.go.dev/github.com/coocood/freecache Entry represents a key-value pair stored in the cache, including its expiration timestamp. ```go type Entry struct { Key []byte Value []byte ExpireAt uint32 } ``` -------------------------------- ### Cache Statistics Source: https://pkg.go.dev/github.com/coocood/freecache Methods for retrieving performance statistics and managing cache state. ```APIDOC ## Cache Statistics ### Description Methods for retrieving performance statistics and managing cache state. ### Methods #### HitCount ```go func (cache *Cache) HitCount() (count int64) ``` **Description:** Returns the number of cache hits. #### MissCount ```go func (cache *Cache) MissCount() (count int64) ``` **Description:** Returns the number of cache misses. #### LookupCount ```go func (cache *Cache) LookupCount() int64 ``` **Description:** Returns the total number of lookups performed. #### HitRate ```go func (cache *Cache) HitRate() float64 ``` **Description:** Returns the cache hit rate as a float64. #### AverageAccessTime ```go func (cache *Cache) AverageAccessTime() int64 ``` **Description:** Returns the average Unix timestamp when an entry was last accessed. Entries with older access times are prioritized for eviction. #### EvacuateCount ```go func (cache *Cache) EvacuateCount() (count int64) ``` **Description:** Returns the number of entries that have been evacuated from the cache. #### ExpiredCount ```go func (cache *Cache) ExpiredCount() (count int64) ``` **Description:** Returns the number of entries that have expired. #### OverwriteCount ```go func (cache *Cache) OverwriteCount() (overwriteCount int64) ``` **Description:** Returns the number of times entries were overwritten due to cache being full. #### TouchedCount ```go func (cache *Cache) TouchedCount() (touchedCount int64) ``` **Description:** Returns the number of times entries had their expiration time updated. #### EntryCount ```go func (cache *Cache) EntryCount() (entryCount int64) ``` **Description:** Returns the current number of entries in the cache. #### Clear ```go func (cache *Cache) Clear() ``` **Description:** Clears all entries from the cache. #### ResetStatistics ```go func (cache *Cache) ResetStatistics() ``` **Description:** Resets all cache statistics to zero. ``` -------------------------------- ### Iterator Source: https://pkg.go.dev/github.com/coocood/freecache Provides functionality to iterate over the entries in the cache. ```APIDOC ## Iterator ### Description Provides functionality to iterate over the entries in the cache. ### Type #### Iterator ```go type Iterator ``` ### Methods #### NewIterator ```go func (cache *Cache) NewIterator() *Iterator ``` **Description:** Creates a new iterator for the cache. #### Next ```go func (it *Iterator) Next() *Entry ``` **Description:** Returns the next entry in the iteration. Returns nil if there are no more entries. ``` -------------------------------- ### Cache Operations Source: https://pkg.go.dev/github.com/coocood/freecache Methods for interacting with the cache, including setting, retrieving, and updating entries. ```APIDOC ## Set ### Description Sets a key, value, and expiration for a cache entry. ### Parameters - **key** ([]byte) - Required - The key to store. - **value** ([]byte) - Required - The value to store. - **expireSeconds** (int) - Required - Expiration time in seconds. <= 0 means no expire. ## Peek ### Description Returns the value or not found error without updating access time or counters. No expiry check is performed. ### Parameters - **key** ([]byte) - Required - The key to look up. ## SetAndGet ### Description Sets a key/value and returns the existing value if the record was found. ### Parameters - **key** ([]byte) - Required - The key to store. - **value** ([]byte) - Required - The value to store. - **expireSeconds** (int) - Required - Expiration time in seconds. ## Update ### Description Atomically gets a value and passes it to an updater function to decide if a new value should be set. ### Parameters - **key** ([]byte) - Required - The key to update. - **updater** (Updater) - Required - Function to determine if a set operation should occur. ``` -------------------------------- ### Multi-key Retrieval Source: https://pkg.go.dev/github.com/coocood/freecache Retrieves multiple values for a slice of keys, reducing lock contention. ```go func (cache *Cache) MultiGet(keys [][]byte) (values [][]byte, errs []error) ``` -------------------------------- ### Cache Metadata and Statistics Source: https://pkg.go.dev/github.com/coocood/freecache Methods for retrieving TTL information and managing cache statistics. ```APIDOC ## TTL ### Description Returns the time left for a given key or a not found error. ### Parameters - **key** ([]byte) - Required - The key to check. ## Touch ### Description Updates the expiration time of an existing key. ### Parameters - **key** ([]byte) - Required - The key to update. - **expireSeconds** (int) - Required - New expiration time. ## ResetStatistics ### Description Refreshes the current state of the statistics. ``` -------------------------------- ### Peek Cache Entry and Expiration Time Source: https://pkg.go.dev/github.com/coocood/freecache PeekWithExpiration retrieves a cache entry's value and its expiration timestamp without updating access time or counters. Warning: This method does not perform an expiry check, so expired values may be returned. ```go func (cache *Cache) PeekWithExpiration(key []byte) (value []byte, expireAt uint32, err error) ``` -------------------------------- ### Atomically Update Cache Entry Based on Existing Value Source: https://pkg.go.dev/github.com/coocood/freecache Update atomically retrieves a value for a key, passes it to an updater function, and conditionally calls Set based on the updater's decision. It returns whether the key was found, if the value was replaced, and any error encountered. Adheres to size constraints, and an expireSeconds value of 0 or less means no expiration but potential eviction. ```go func (cache *Cache) Update(key []byte, updater Updater) (found bool, replaced bool, err error) ``` -------------------------------- ### Define Hash Entry Size Constant Source: https://pkg.go.dev/github.com/coocood/freecache Defines the size of a hash entry in bytes. This constant is used for internal hash table calculations. ```go const HASH_ENTRY_SIZE = 16 ``` -------------------------------- ### Set Integer Key with Cache Entry Source: https://pkg.go.dev/github.com/coocood/freecache SetInt stores a byte slice value associated with an int64 key, with a specified expiration time. It follows the same size and expiration logic as the Set method. ```go func (cache *Cache) SetInt(key int64, value []byte, expireSeconds int) (err error) ``` -------------------------------- ### Peek at Cache Entry Without Updating Access Time Source: https://pkg.go.dev/github.com/coocood/freecache Use Peek to retrieve a cache entry's value without affecting its access time or counters. Warning: This method does not perform an expiry check, so expired values may be returned. ```go func (cache *Cache) Peek(key []byte) (value []byte, err error) ``` -------------------------------- ### RingBuf Source: https://pkg.go.dev/github.com/coocood/freecache A circular buffer implementation used internally by Freecache. ```APIDOC ## RingBuf ### Description A circular buffer implementation used internally by Freecache. ### Type #### RingBuf ```go type RingBuf ``` ### Functions #### NewRingBuf ```go func NewRingBuf(size int, begin int64) (rb RingBuf) ``` **Description:** Creates a new RingBuf with the specified size and starting position. ### Methods #### Begin ```go func (rb *RingBuf) Begin() int64 ``` **Description:** Returns the starting position of the buffer. #### End ```go func (rb *RingBuf) End() int64 ``` **Description:** Returns the ending position of the buffer. #### Size ```go func (rb *RingBuf) Size() int64 ``` **Description:** Returns the total size of the buffer. #### Reset ```go func (rb *RingBuf) Reset(begin int64) ``` **Description:** Resets the buffer to a new starting position. #### Resize ```go func (rb *RingBuf) Resize(newSize int) ``` **Description:** Resizes the buffer to a new size. #### Skip ```go func (rb *RingBuf) Skip(length int64) ``` **Description:** Skips a specified number of bytes from the beginning of the buffer. #### Slice ```go func (rb *RingBuf) Slice(off, length int64) ([]byte, error) ``` **Description:** Returns a slice of the buffer data at a given offset and length. #### Dump ```go func (rb *RingBuf) Dump() []byte ``` **Description:** Returns a byte slice containing the entire contents of the buffer. #### EqualAt ```go func (rb *RingBuf) EqualAt(p []byte, off int64) bool ``` **Description:** Checks if a byte slice is equal to the buffer content at a specific offset. #### ReadAt ```go func (rb *RingBuf) ReadAt(p []byte, off int64) (n int, err error) ``` **Description:** Reads data from the buffer into a byte slice at a specific offset. #### Write ```go func (rb *RingBuf) Write(p []byte) (n int, err error) ``` **Description:** Writes data to the buffer. The write position advances automatically. #### WriteAt ```go func (rb *RingBuf) WriteAt(p []byte, off int64) (n int, err error) ``` **Description:** Writes data to the buffer at a specific offset. #### Evacuate ```go func (rb *RingBuf) Evacuate(off int64, length int) (newOff int64) ``` **Description:** Evacuates a specified length of data from the buffer starting at a given offset, returning the new offset. #### String ```go func (rb *RingBuf) String() string ``` **Description:** Returns a string representation of the buffer's contents. ``` -------------------------------- ### Ring Buffer Structure Source: https://pkg.go.dev/github.com/coocood/freecache RingBuf implements a fixed-size ring buffer. When the buffer is full, new data overwrites the oldest data. It maintains data from the beginning to the end of the stream. ```go type RingBuf struct { // contains filtered or unexported fields } ``` -------------------------------- ### Cache Operations Source: https://pkg.go.dev/github.com/coocood/freecache Methods for clearing, deleting, and retrieving items from the cache. ```APIDOC ## Clear ### Description Clears the cache. ## Del ### Description Deletes an item in the cache by key. ### Parameters - **key** ([]byte) - Required - The key to delete. ## DelInt ### Description Deletes an item in the cache by int key. ### Parameters - **key** (int64) - Required - The integer key to delete. ## Get ### Description Returns the value or not found error. ### Parameters - **key** ([]byte) - Required - The key to retrieve. ## GetInt ### Description Returns the value for an integer within the cache or a not found error. ### Parameters - **key** (int64) - Required - The integer key to retrieve. ``` -------------------------------- ### Error for Not Found Entry Source: https://pkg.go.dev/github.com/coocood/freecache Represents an error indicating that a requested entry was not found in the cache. ```go var ErrNotFound = errors.New("Entry not found") ``` -------------------------------- ### Update Expiration Time of an Existing Cache Key Source: https://pkg.go.dev/github.com/coocood/freecache Touch updates the expiration time for an existing cache key. An expireSeconds value of 0 or less indicates no expiration, but the entry may still be evicted if the cache becomes full. ```go func (cache *Cache) Touch(key []byte, expireSeconds int) (err error) ``` -------------------------------- ### Delete Cache Items Source: https://pkg.go.dev/github.com/coocood/freecache Deletes an item by key and returns whether the deletion occurred. ```go func (cache *Cache) Del(key []byte) (affected bool) ``` ```go func (cache *Cache) DelInt(key int64) (affected bool) ``` -------------------------------- ### Cache Iterator Structure Source: https://pkg.go.dev/github.com/coocood/freecache Iterator is used to iterate over the entries within the cache. The order of iteration is not guaranteed. ```go type Iterator struct { // contains filtered or unexported fields } ``` -------------------------------- ### Reset Cache Statistics Source: https://pkg.go.dev/github.com/coocood/freecache ResetStatistics refreshes the current state of the cache's statistics. ```go func (cache *Cache) ResetStatistics() ``` -------------------------------- ### Error for Out of Range Access Source: https://pkg.go.dev/github.com/coocood/freecache Represents an error indicating an attempt to access data outside the valid range. ```go var ErrOutOfRange = errors.New("out of range") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.