Skip to content

A simple, efficient, thread-safe <130 loc in-memory data store with expiration time

Notifications You must be signed in to change notification settings

ArchishmanSengupta/cache-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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": "johndoe@example.com"}
Enter expiration time (seconds): 30
Cache value: {"name": "John Doe", "age": 30, "email": "johndoe@example.com"}
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!

About

A simple, efficient, thread-safe <130 loc in-memory data store with expiration time

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages