#cache #lru-cache #lock-free #concurrency #lfu #shared-state

bin+lib cache-advisor

防扫描的并发缓存淘汰管理器

9 个稳定版本

1.0.16 2023 年 8 月 5 日
1.0.15 2023 年 7 月 11 日
1.0.14 2023 年 6 月 25 日
1.0.13 2023 年 4 月 29 日
1.0.11 2022 年 6 月 12 日

28缓存

Download history 43/week @ 2024-03-11 48/week @ 2024-03-18 41/week @ 2024-03-25 78/week @ 2024-04-01 61/week @ 2024-04-08 53/week @ 2024-04-15 34/week @ 2024-04-22 54/week @ 2024-04-29 42/week @ 2024-05-06 43/week @ 2024-05-13 34/week @ 2024-05-20 88/week @ 2024-05-27 88/week @ 2024-06-03 54/week @ 2024-06-10 80/week @ 2024-06-17 73/week @ 2024-06-24

321 每月下载次数

MIT/Apache

34KB
620

cache-advisor

文档

告诉您何时从缓存中删除项目。应在现代服务器硬件上能够承受数千万次每秒的访问而不会出现任何阻塞。

特性

  • 双段 LRU,防止单次命中项污染缓存
  • 通过无阻塞 flatcombining 访问 256 个分片
  • 在访问共享状态之前必须填满的本地访问缓冲区
  • 使用一种压缩技术将每个项目的成本压缩为 u8,这种压缩技术将在一段时间内收敛到总成本的真实总和,但允许用于计账的内存使用量大大减少。

API

impl CacheAdvisor {
  /// Instantiates a new two-segment `CacheAdvisor` eviction manager.
  ///
  /// Choose an overall size and the percentage 0..=100 that should
  /// be devoted to the entry cache. 20% is a safe default.
  pub fn new(capacity: usize, entry_percent: u8) -> CacheAdvisor { .. }

  /// Mark items that are accessed with a certain cost.
  /// Returns the items that should be evicted and their associated costs.
  /// The returned costs are always a compressed power of two and may not
  /// be the exact cost that you set for an item. Over time it converges
  /// to a correct value, however.
  pub fn accessed(&mut self, id: u64, cost: usize) -> Vec<(u64, usize)> { .. }

  /// Similar to `accessed` except this will reuse an internal vector for storing
  /// items to be evicted, which will be passed by reference to callers. If the
  /// returned slice is huge and you would like to reclaim underlying memory, call
  /// the `reset_internal_access_buffer` method. This can improve throughput by around
  /// 10% in some cases compared to the simpler `accessed` method above (which may
  /// need to copy items several times as the returned vector is expanded).
  pub fn accessed_reuse_buffer(&mut self, id: u64, cost: usize) -> &[(u64, usize)] { .. }

  /// Resets the internal access buffer, freeing any memory it may have been holding
  /// onto. This should only be called in combination with `accessed_reuse_buffer` if
  /// you want to release the memory that the internal buffer may be consuming. You
  /// probably don't need to call this unless the previous slice returned by
  /// `accessed_reuse_buffer` is over a few thousand items long, if not an order of magnitude
  /// or two larger than that, which should ideally be rare events in workloads where
  /// most items being inserted are somewhat clustered in size.
  pub fn reset_internal_access_buffer(&mut self) { .. }
}

依赖项

~155KB