lrucache is a thread-safe, high-performance Least Recently Used (LRU) cache implementation in Go with the simplest of APIs.
We are improving our reverse proxy and needed a more efficient caching mechanism for DNS records.
- Thread-Safe: Uses
sync.RWMutex
to handle concurrent read/write operations safely. - High Performance: Optimized for frequent access and rapid insertion/eviction.
- Customizable Capacity: Configure the cache size to suit your application's needs.
- Hit/Miss Tracking: Monitor cache performance with hit/miss statistics.
import "github.com/ipv6rslimited/lrucache"
cache := lrucache.NewLRUCache(100)
cache.Put("key1", "value1")
value, found := cache.Get("key1")
if found {
fmt.Println("Found:", value)
} else {
fmt.Println("Not found")
}
import "fmt"
hits, misses := cache.GetHitMissCount()
fmt.Printf("Hits: %d, Misses: %d\n", hits, misses)
- Frequent Access: Ensures that frequently accessed items are not evicted.
- Rapid Insertion/Eviction: Verifies cache behavior under rapid insertions and evictions.
- Hit/Miss Ratio: Validates the accuracy of hit/miss tracking.
- Large Data Set: Tests cache performance with a large number of items.
- Boundary Conditions: Checks edge cases, such as zero capacity and large value sizes.
- High Concurrency Stress: Tests cache performance under high concurrency.
- Extreme Edge Cases: Ensures the cache handles extreme scenarios gracefully.
You can run a pretty sweet suite of tests by typing:
go test
Distributed under the COOL License.
Copyright (c) 2024 IPv6.rs https://ipv6.rs All Rights Reserved