Documentation ¶
Overview ¶
Package distributed_cache contains all necessary files to add a distributed cache to your application. The communication between nodes using UDP.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { Name string // Name of the cache Address string // Port over which the cache will communicate Broadcast string // Broadcast addresses 255.255.255.255 for IPV4 all network StopListener context.CancelFunc // Cancel function // to stop the listener Filler func(string) (interface{}, error) // Function to fill the cache // when the key is not found RemoveHook func(string, interface{}) // Function to remove the key from the cache // contains filtered or unexported fields }
Cache is a simple cache interface, to create a cache you must Use NewCache Method
func NewCache ¶
NewCache creates a new Cache with the given name and address It also starts a listener to receive messages from other nodes
func (*Cache) Clean ¶
func (c *Cache) Clean()
Clean deletes all values from the cache and sends the sendClean message to the other nodes
type LRUCache ¶
LRUCache is a cache that uses the Least Recently Used algorithm to evict entries
func NewLRUCache ¶
func (*LRUCache) Clean ¶
func (c *LRUCache) Clean()
Clean deletes all values from the cache and sends the sendClean message to the other nodes
type LRUCacheWithTTL ¶
type LRUCacheWithTTL struct { LRUCache TTL time.Duration // contains filtered or unexported fields }
LRUCacheWithTTL is a cache that uses the Least Recently Used (LRU) algorithm to evict entries when the cache is full. It also has a time-to-live (TTL) for each entry if an entry is not accessed, it will be deleted after the TTL expires. The Evict method is called periodically (TTL Period) to delete entries that have expired.
func NewLRUCacheWithTTL ¶
func NewLRUCacheWithTTL(name, broadcast, address string, maxEntries int, ttl time.Duration) *LRUCacheWithTTL
NewLRUCacheWithTTL creates a new LRUCacheWithTTL with the given name, address, maxEntries and TTL. It also starts a listener to receive messages from other nodes and starts a for cache eviction. name is the name of the cache address is the address of the cache maxEntries is the maximum number of entries that the cache can have ttl is the time-to-live for each entry in the cache
func (*LRUCacheWithTTL) Clean ¶
func (c *LRUCacheWithTTL) Clean()
Clean deletes all values from the cache and sends the sendClean message to the other nodes
func (*LRUCacheWithTTL) Delete ¶
func (c *LRUCacheWithTTL) Delete(key string)
Delete deletes a value from the cache and sends the delete message to the other nodes
func (*LRUCacheWithTTL) Get ¶
func (c *LRUCacheWithTTL) Get(key string) interface{}
Get gets a value from the cache
func (*LRUCacheWithTTL) Set ¶
func (c *LRUCacheWithTTL) Set(key string, value interface{})