Skip to content

ametow/sieve-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Implementing a Sieve cache in Go

Unlike traditional caching systems that might use standard policies (e.g., LRU, LFU), a sieve cache focuses on selective and adaptive caching based on specific filtering rules or algorithms tailored to the use case.

Sieve Cache

A sieve cache is a caching mechanism designed to optimize the delivery of frequently accessed content in a highly efficient and selective manner. The concept typically refers to how data is stored and retrieved in systems that require filtering or partitioning based on certain criteria, resembling a sieve’s selective filtering.

Key Characteristics of a Sieve Cache

  1. Selective Caching: Stores only specific, high-value or frequently accessed data. Often used in scenarios where caching everything is not feasible due to size or relevance constraints.

  2. Efficient Filtering: Employs algorithms to “sift” through data and decide what should be cached or evicted. May use metrics like frequency of access, recency, or custom rules to filter content.

  3. Adaptive Mechanism: Dynamically adjusts the cached data based on changing patterns or criteria. Ensures that the cache remains relevant to current workloads.

  4. Low Latency: Designed for fast access, typically in systems requiring real-time data processing.

Explanation

  1. Filter Function: A sieveFilter function determines if an item should be cached. It’s customizable based on your use case.

  2. TTL: Cached items have a time-to-live (ttl). Expired items are automatically removed during periodic cleanup.

  3. Cleanup: A background goroutine periodically scans and removes expired items.

  4. Concurrency: The sync.Map ensures thread-safe read and write operations.

  5. Graceful Stop: The Stop method cleans up resources and stops the cleanup goroutine.

Comparison with LRU cache

LRU Cache

Optimized for scenarios where the most recently used items are likely to be accessed again. Evicts the least recently used items to make room for new ones.

Sieve Cache

Optimized for filtering data before caching based on custom logic (sieve filter). Evicts items based on a time-to-live (TTL) expiration policy.

Applications of Sieve Cache

  • Content Delivery Networks (CDNs): To cache popular or geographically relevant web resources.
  • AdTech: To cache user targeting rules, ad creatives, or bid responses that are frequently used.
  • Database Query Optimization: For selective query result caching to reduce database load.
  • Streaming Services: To cache chunks of video or audio data based on user behavior.

About

Sieve cache implementation in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages