Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.91 KB

README.md

File metadata and controls

44 lines (33 loc) · 1.91 KB

Cache Store

Cache Store is a simple, efficient, and thread-safe in-memory cache library for Go. It allows you to store key-value pairs with optional expiration times, making it an ideal choice for caching frequently accessed data to improve application performance.

Use Case

Cache Store can be used in various scenarios where caching is beneficial, such as:

  • Caching API responses to reduce latency and minimize the number of requests to external services.
  • Storing frequently accessed data, like session data or user preferences, to improve application performance.
  • Implementing a least recently used (LRU) cache for efficient memory management.

Here's an example of using Cache Store:

Enter value: {"name": "John Doe", "age": 30, "email": "[email protected]"}
Enter expiration time (seconds): 30
Cache value: {"name": "John Doe", "age": 30, "email": "[email protected]"}
Key not found in cache

Features:

  1. Optional expiration caching
  2. Thread-safe design
  3. Automatic expired cleanup
  4. Comprehensive cache ops
  5. Proper error handling

Benchmarking

To run benchmarks, use the following command:

go test -bench=. -benchmem -cpu 12

Example benchmark results on a macOS (Darwin) system with an ARM64 architecture:

BenchmarkCache_SetValue/Set-0-12                 7123024               144.6 ns/op            72 B/op          4 allocs/op
BenchmarkCache_GetValue/Get-0-12                30922952                38.03 ns/op            0 B/op          0 allocs/op
BenchmarkCache_Iterate/Iterate-12                 110947             10935 ns/op              16 B/op          1 allocs/op

These benchmarks demonstrate the performance of Cache Store's core functions, such as setting, getting, and iterating over cache items.

Contribution

Contribute to the project, report issues, or request features by opening a pull request or an issue.

Happy caching!