cache

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 3 Imported by: 0

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 defines the structure of the cache, including a map for quick lookup, a doubly linked list to maintain order, a mutex for concurrent access, a size limit, and a tag for logging.

func NewCache

func NewCache(size int, tag string) *Cache

NewCache initializes a new cache with the specified size and tag, and logs the initialization event.

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items from the cache.

func (*Cache) DeleteItem

func (c *Cache) DeleteItem(key string)

DeleteItem removes an item from the cache based on its key.

func (*Cache) GetAllItems

func (c *Cache) GetAllItems() []*CacheItem

GetAllItems returns a slice containing all items in the cache.

func (*Cache) GetItem

func (c *Cache) GetItem(key string) (*CacheItem, bool)

GetItem retrieves an item from the cache based on its key, marking the item as recently used if found.

func (*Cache) GetItems

func (c *Cache) GetItems(pageNum int, pageSize int) []*CacheItem

GetItems returns a slice of CacheItems from the cache, based on the specified pagination parameters.

func (*Cache) GetMaxSize

func (c *Cache) GetMaxSize() int

GetMaxSize returns the maximum size of the cache.

func (*Cache) GetTotalItems

func (c *Cache) GetTotalItems() int

GetTotalItems returns the total number of items currently in the cache.

func (*Cache) SetItem

func (c *Cache) SetItem(key string, value interface{})

SetItem adds a new item to the cache or updates an existing one, while managing the size limit and eviction policy.

type CacheItem

type CacheItem struct {
	Key   string
	Value interface{}
}

CacheItem represents a single item in the cache, holding a key and its associated value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL