cache

package
v0.0.0-...-b97d05d Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 5 Imported by: 0

README

Cache

This implementation provides a scalable solution using a combination of an LRU cache and a Bloom Filter to efficiently manage APRS packet storage while reducing duplicate transmissions.

Usage Example

func main() {
	cache := NewCache(1000, 10000, "cache.json") // Capacity of 1000 for LRU, Bloom filter size of 10,000 items

	// Example APRS entries
	entries := []string{
		"APRS: N7RIX-7>T0QPSP,WIDE1-1,WIDE2-1:`AYl\"<[/`\"C0}_3",
		"APRS: N7RIX-7>T0QPSP,WIDE1-1,WIDE2-2:`AYl\"<[/`\"C0}_4",
		"APRS: N7RIX-7>T0QPSP,WIDE1-1,WIDE2-3:`AYl\"<[/`\"C0}_5",
		"APRS: N7RIX-7>T0QPSP,WIDE1-1,WIDE2-1:`AYl\"<[/`\"C0}_3", // Duplicate
	}

	for _, entry := range entries {
		isDuplicate := cache.Set(entry, entry)

        if isDuplicate {
            fmt.Println("Duplicate entry")
        }
	}

	// Check cache contents
	for _, entry := range entries {
		value, exists := cache.Get(entry)
		if exists {
			fmt.Printf("Entry found in cache: %v\n", value)
		} else {
			fmt.Printf("Entry not found in cache: %v\n", entry)
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BloomFilter

type BloomFilter struct {
	// contains filtered or unexported fields
}

func NewBloomFilter

func NewBloomFilter(size uint) *BloomFilter

func (*BloomFilter) Add

func (bf *BloomFilter) Add(data []byte)

func (*BloomFilter) Test

func (bf *BloomFilter) Test(data []byte) bool

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache(capacity int, filePath string) *Cache

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}) (duplicate bool)

type LRU

type LRU struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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